Proper way to include data with an HTTP PATCH request

Alexander Trauzzi picture Alexander Trauzzi · Jun 29, 2013 · Viewed 17.4k times · Source

When I'm putting together an HTTP PATCH request, what are my options to include data outside of URL parameters?

Will any of the following work, and what's the most common choice?

  • multipart/form-data
  • application/x-www-form-urlencoded
  • Raw JSON
  • ...any others?

Answer

rdlowrey picture rdlowrey · Jun 29, 2013

There are no restrictions on the entity bodies of HTTP PATCH requests as defined in RFC 5789. So in theory, your options in this area are unlimited.

In my opinion the only sensible choice is to use the same Content-Type used to originally create the resource. The most common choice is application/json simply because most modern APIs utilize JSON as their preferred data transfer format.

The only relevent statement RFC 5789 makes in regard to what should and shouldn't be part of your PATCH entity body is silent on the matter of Content-Type:

the enclosed entity contains a set of instructions describing how a resource currently residing on the origin server should be modified to produce a new version.

In summary, how you choose to modify resources in your application is entirely up to you.