简体   繁体   中英

Multiple ID's in REST endpoints

coming from a Wordpress background my knowledge on using REST API's is quite limited. I've started using JSON server (dummy local rest API) to learn the ins and outs.

Looking at the documentation, there doesn't seem to be any way to delete, update or post multiple items in one go? The PATCH , POST , PUT and DELETE methods all require an endpoint structured with one trailing ID eg /posts/1 . I've tried both sending multiple ID's in the url ie ?id=1&id=2 and also as part of the request body but neither seem to work.

Is this how typical REST API's work, and if so does this mean i would have to loop though ID's and send multiple requests for each, or am i missing the point??

With REST, you don't typically have bulk operations, unless you are, say, deleting a collection. A POST request usually inserts a single entity into a collection, although that doesn't mean that you CANNOT construct the endpoint to accept an array of entities to insert into the collection. When I design a RESTful endpoint for POSTing a new resource, I only accept a single entity. I leave it up to the client to perform multiple POST requests in parallel to reduce the time it takes to create the list of entities.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM