...

/

Design the PUT Endpoint for Updating an Existing Product

Design the PUT Endpoint for Updating an Existing Product

Understand the PUT method and design the products API to update an existing product.

To update an existing entry in the collection, we use the PUT method.

Updating an existing product

According to the specificationsRFC2616, “The PUT method requests that the enclosed entity be stored under the supplied Request-URI. If the Request-URI refers to an already existing resource, the enclosed entity SHOULD be considered as a modified version of the one residing on the origin server. If the Request-URI does not point to an existing resource, and that URI is capable of being defined as a new resource by the requesting user agent, the origin server can create the resource with that URI. If a new resource is created, the origin server MUST inform the user agent via the 201 (Created) response.”

So, PUT can be used for creating a new product as well as updating an existing product. However, creating a new product using PUT is not generally recommended or practised.

Based on the above definition, the following are the main features of the PUT method:

  • The Request-URI refers to an existing item.
  • The entity provided within the body has to be used
...
Access this course and 1400+ top-rated courses and projects.