0

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??

Samuel
  • 2,485
  • 5
  • 30
  • 40
  • Why you don't pass a list of ID's? – DiPix Jun 25 '17 at 08:14
  • What are you trying to achieve? You cannot send same query param in a url twice. It will be overridden. Keys of your query params need to be different – Prabodh M Jun 25 '17 at 08:16
  • Say for example, i want to `DELETE` entires with ID's `1`,`2`, `3`, `4`, in `/todos` how would i send those ID's using fetch? Things i've tried that don't work: `fetch('http://localhost:3000/todos?id=1&id=2&id=3&id=4', {method: 'DELETE'});` `fetch('http://localhost:3000/todos', { method: 'DELETE', body: [{id:1}, {id:2}, {id: 3}, {id: 4}] } });` – Samuel Jun 25 '17 at 08:34
  • What r u using for backend? .NET? – DiPix Jun 25 '17 at 08:39

1 Answers1

0

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.

Joshua Jones
  • 1,364
  • 1
  • 9
  • 15