Requests to the REST API made as follows.

 GET http://v1/resource/ // получить все данные ресурса resource GET http://v1/resource?fild1=5&Fild2=6 // получить все данные ресурса resource где поле fild1 равно 5 и поле Fild2 равно 6 (количество параметров произвольно) GET http://v1/resource?id=5 // получить ресурс resource с айди 5 POST http://v1/resource/ // создать ресурс resource со значением поля foo равно bar body {foo: 'bar'} PUT http://v1/resource?id=5 // отредактировать ресурс resource с айди 5 изменив значение foo на bar body {foo: 'bar'} DELETE http://v1/resource?id=5 // удалить ресурс resource с айди 5 

Thus, we issued all CRUD operations to our resource.

The question is, what if we need to change not one record but 5? Then the query will have the following form?

 PUT http://v1/resource?id=1,2,3,4,5 body [{foo: 'on_store'}, {foo: 'on_store'}, {foo: 'on_store'}, {foo: 'on_store'}, {foo: 'on_store'}] 

Or do I need to contact api each time in a separate request?

 PUT http://v1/resource?id=1 body {foo: 'on_store'} PUT http://v1/resource?id=2 body {foo: 'on_store'} PUT http://v1/resource?id=3 body {foo: 'on_store'} PUT http://v1/resource?id=4 body {foo: 'on_store'} PUT http://v1/resource?id=5 body {foo: 'on_store'} 

And if there are several thousand or tens of thousands of such objects (for example, a change in status in a certain range of goods, or a very large list of goods where the IDs go out of order)?

Can I make my api like this?

 PUT http://v1/resource body [{ id: 1, foo: 'on_store' }, { id: 2, foo: 'on_store' }, { ... }, { id: n, foo: 'on_store' }] 

And knowing that it is PUT transmit the id object to be changed in the request body next to the fields that need to be changed?

  • 2
    In general, the last option is quite viable. - Nofate
  • I firmly believe that the ideology of REST is more recommendatory than incentive. Do not blindly and mindlessly follow her. I would choose the last option, possibly with a postscript batch (Which is also out of the recommendation) PUT http://v1/resource/batch - Oleg

0