in Uncategorized

Using PATCH

Now that HTTP PATCH is official, would lack of standard media types and patch formats to describe partial updates to resource hamper its adoption? Most likely not.

The problem with any write request is maintaining integrity of the data in the backend. When a client submits POST or PUT requests, the server has to ensure that the representation in the request is consistent with the business rules that govern what is valid and what is not. The media types used for representations along with documentation can describe client developers how to make such write requests that honor server's business rules.

The introduction of PATCH complicates this a bit more. In addition to describing valid resource representations for creating, updating, or doing other kinds of things with POST and DELETE, the server now needs to tell clients what combinations of partial updates are valid for use with the PATCH method. General diff formats would leave the door open for clients to submit invalid combinations of partial updates that violate the business rules on the server side. To avoid this, it is better to come up with application specific representations for partial updates. See How to Use PATCH for an example. Lack of standard media type for diffs should not hold you from using the PATCH method.

Write a Comment

Comment

  1. Urgh. So, what value is PATCH bringing to the table if you need application-specific diff formats? Why not just use POST?

    I’d rather live in a world where the applications “business rules” weren’t so tied up in the representation that you can’t update a bit of state without breaking something. Sure, this isn’t going to fit all applications, but maybe those applications shouldn’t be using PATCH…

  2. So, what value is PATCH bringing to the table if you need application-specific diff formats? Why not just use POST?

    Good question – but I don’t see how PATCH is related to the representation format. IMO, these are orthogonal. Moreover, I am not sure if you can keep application specifics away from the representation formats. We tried with Atom, and we know how well it went.

  3. When you describe using PATCH in this way, doesn’t it seem like PATCH just becomes a way to tunnel a method invocation? So far, I’d just much rather model this in hypermedia.

  4. @Bill: Yes – PATCH can inherently seem like tunneling a number of write instructions (such as increment X, delete Y, add Z etc.) in a single representation. Is that tunneling? Perhaps. If those micro updates need to be visible at the protocol level, then PATCH is the wrong method to use. If not, I don’t see a problem.