Reputation: 301
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?
Upvotes: 6
Views: 1146
Reputation: 39296
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
Upvotes: 4
Reputation:
Yes, PUT
should provide the complete new representation of the resource. So Id
and Foo
should be removed on the server.
If you just want to update Bar
, POST
{"Bar": "newBarValue"}
to it.
As often in REST, this is only a convention.
Upvotes: 0