1

Let's say I have a resource Resource1 with an attribute String attr1. I want to support the update of atrr1 by the PATCH verb.

I understand that in this case, where the attribute is not an array, both the add and replace operations will do the same - replacing the attribute's value.

So in this case what is the correct way to update the attribute, using add or replace? what are the considerations?

At my work they decided to use the add operation and I'm trying to figure out if it was the right decision.

YevgenyL
  • 281
  • 3
  • 20
  • It depends on the media type of the PATCH request; which one are you trying to use? – Julian Reschke Jun 03 '16 at 08:59
  • The media type is application/json , but I don't see the connection to media type. In both cases you can use add and replace, but the question what is the correct way in this case? – YevgenyL Jun 03 '16 at 09:40
  • The semantics of PATCH depend on the media type of the payload. For application/json, AFAIK, there are no defined semantics, so it shouldn't be used with PATCH (at least if you're interested in interop). See RFC 6902 and RFC 7396 for media types that have been specified for use with PATCH. – Julian Reschke Jun 03 '16 at 11:39
  • When you say "application/json", are you referring to what's sent with the PATCH request, or to the resource being patched? – Julian Reschke Jun 03 '16 at 14:07
  • Ok. So no, using application/json as payload for PATCH has no defined semantics, so I wouldn't use it. – Julian Reschke Jun 03 '16 at 15:59
  • The PATCH is in use, because we don't want to use PUT to update the resource. In this way we'll need to send the entire resource data in PUT. – YevgenyL Jun 03 '16 at 16:58
  • 1
    That's fine. Just use a media type as payload which has defined PATCH semantics, such as those defined in RFCs 6902 or 7396. – Julian Reschke Jun 04 '16 at 06:01

1 Answers1

1

The semantics of an HTTP PATCH operation depend mainly on the media type used in the payload. PATCH operations should not be done with payloads that do not have defined patch semantics, such as application/json (see https://www.rfc-editor.org/errata_search.php?rfc=5789&eid=3169).

As far as I know, there are currently two patch formats defined for JSON; their specs are in the RFCs 6902 and 7396.

Julian Reschke
  • 40,156
  • 8
  • 95
  • 98