PUT Versus PATCH

For PUT methods the resource data is replaced with the data specified in the request. All fields of the resource are replaced with the fields in the request.

This means that:

  • Fields not present in the request that are present in the resource will be dropped from the resource.
  • Fields present in the request that are not present in the resource will be appended to the resource.
  • The data of fields present in the request is used to update fields that already exist in the resource.

PATCH methods operate in two modes depending on the content type:

  • Content type: application/json
  • The values of data fields present in the request is used to update the corresponding resource fields. This means that:
    • Fields present in the request but not in the resource is appended to the resource.
    • The value of each field that is already present in the resource is updated from the request data.
    • Field values that are set to null in the request is dropped from the resource.
    • Fields that are present in the resource but not in the request are left untouched.
  • Content type: application/json-patch+json
    • Existing resource data is patched according to RFC6902.

Modifying data fields:

  • To drop the field from a data model, specify null as the parameter value (i.e. {"field": null}).
  • To blank out a string value set the parameter value to an empty string (i.e. {"field":""}).