PATCH, POST & PUT

This article will explain when to use each of the verbs and any nuances.

Post

The POST verb allows you to create a new object. All required fields must be in the payload. Let's create a country with the following details:

We note the response:

PUT

The PUT verb allows you to update properties of an object. You must use the update request header and supply only the properties that need updating with the Update Request header. For more details see Update Requests

Patch

The PATCH verb allows you to update an object. Just like a put, you only need to supply the fields that will be updated in the payload. However, a patch allows you to update many objects at once. Many objects in EngageIP are hierarchical in nature - consider an account package that has services and those services in turn have usage identifiers. To update the parent object we would use PUT. But, if you want to update one or more of the children/grandchildren use PATCH. Patch offers a couple of benefits over PUT in that:

  • Patch operations are transactional - if an update fails anywhere in the hierarchy the entire transaction is rolled back so you are not caught with a partial update
  • Object relationships can be implied by the data structure so you are free from the burden of determining the foregin key - If you are updating the usage identifier on an account service you do not have to worry about the account service or an linking tables since you are sending the structure.
Rule of Thumb: Use PUT for parent updates, Use PATCH for children

Delete

You can delete an object as long as it is not referenced by another entity.