Search code examples
restpartialput

REST: PUT and how to handle partial entity


I've read all about idem potency of PUT and not to use it for partial updates. My question now is how to handle such situations.

Assume my service gets a PUT request for Resource A. A has 5 properties. What do I do if the request only contains 4 of those?

  • Set the missing property to null
  • throw error, 400 Bad Request
  • other?

Setting to null seems ok when creating a new resource but seems possibly problematic or dangerous when updating.

Which is considered "best practice" for this scenario?


Solution

  • According to the Book REST in Practice:

    • PUT expects the entire resource representation
    • PATCH has been suggested for use in situations—typically involving large resource representations where only changes are provided