Search code examples
httprestput

How HTTP PUT should work


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?


Solution

  • 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