Below are the difference between a POST and a PUT HTTP Methods:
Point of Distinction | Post | Put |
---|---|---|
Idempotent | Not Idempotent. If you put a resource twice it will create record with same information. In case a request is retried multiple times, then multiple resources with equal number of URIs gets created on the server. | Idempotent. If you put a resource twice it has no effect. In case the user sends multiple retries of the same request, then each request is equal to a specific/ singular request modification. |
Best Practice or general Application | Always use Post for Create operation. | Always use put for update operation. It replace existing resource or create new if not exist. |
Example | Post /order. To create new order. | Put /order/1 . To modify order id 1. |
Request for | The POST method requests the origin server to accept the entity that is enclosed in the request. The acceptance has to be in the form of a new subordinate of the identified resource, as stated by the Request-URI under the Request-Line. | RFC-2616 states that the PUT method places a request for an enclosed entity to be stored in the supplied Request-URI. |
Action | The action of this command essentially pertains to the POST request-URI being a collection URI. | In case the Request-URI relates to an existing resource then an update type of operation will take place. Else, a create operation occurs in case the Request-URI happens to be a valid resource URI. This is under the assumption that the client is permitted to assess the resource identifier. |
Usage | POST is used when the request pertains to adding a child resource in the existing resources collection. | PUT is utilized when modifications to a singular resource, which already exists in the resources collection, is requested. PUT will replace the resource completely. The PATCH command is to be used in case the request relates to updating a specific portion of the resource. |
Caching of Response | Responses to POST cannot be cached. The exception being when the response expires the header fields or incorporates appropriate cache control elements. | As PUT is idempotent, the response can be cached. |