REST updates several resources

I tried to search for this, but I could not find an answer that would fit my needs.

Given that I have the following route:

[GET] /items 

which can be filtered using query parameters. Now I need to give him the opportunity to immediately add several resources. I reviewed the following query:

 [PATCH] /items 

With such a body:

 id[]=1&id[]=2&id[]=3&updateField=newValue 

I think that something is wrong with this challenge, but I cannot understand it.

+6
source share
1 answer

In the RESTful API, the URL must define the transaction object, and the verb is the action.

So GET /items should return all items.

GET /items/1 should return an element with identifier 1.

It follows that multiple identifiers should be part of the resource definition (url). So GET /items/1,2,3 should return 3 matching elements.

Therefore, to apply a partial update to many identifiers:

 [PATCH] /items/1,2,3 

Then, in the PATCH or PUT body, you can provide updated information (provided that you send the JSON body).

 {"updateField": "newValue"} 
+17
source

Source: https://habr.com/ru/post/922415/


All Articles