Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How HTTP PUT should work

Tags:

rest

http

put

For example, there is resource on URI: /api/items/123

Response body for GET request is {"Id": "123", "Foo": "foo", "Bar": "bar"}

I send PUT request. The body of it is {"Bar": "newBarValue"}

In case of this request body, should properties Id and Foo be removed? Or just Bar property should be modified? Or server should return error code?

like image 346
Denis Sokolov Avatar asked Oct 02 '22 13:10

Denis Sokolov


1 Answers

PUT and GET should use the full resource.

If you just want to update the resource (and just send Bar) then you can also use the PATCH http verb.

A list of restful verbs: https://restful-api-design.readthedocs.org/en/latest/methods.html

like image 197
bryanmac Avatar answered Oct 13 '22 10:10

bryanmac