Technically, you can use the POST method to update an object in an API. However, the more appropriate method for this purpose is the PUT or PATCH method.
The PUT method is specifically designed for updating a resource/ object on a server. It replaces the entire resource with the new data provided in the request. PUT is idempotent, meaning that the same request can be made multiple times, but the outcome will be the same, and the resource will be updated with the latest data.
The PATCH method is used to make partial modifications or updates to a resource/ object. It updates a part of the resource with a new set of data, keeping the other parts of the resource unchanged. PATCH request is non-idempotent, meaning the same request may have different effects with a different outcome each time it is made.
So, if you want to update an object in API, you can use either PUT or PATCH depending on the specific operation you want to perform. While technically possible, using the POST method to update an object goes against HTTP best practices and can make the API’s implementation more confusing and difficult to maintain.
Leave a Reply