What’s is Difference Between POST and PUT

in this restapiexample post, we ll let you know what’s difference between post and put method. The both method are very important into HTTP rest api.The main differences between PUT and POST Requests are discussed in this article.

The post http method is used to cfreate a new resource wheraes put http method is used to updated a existing record.

What is difference between Post and Put

The PUT method is idempotent. So if we retry a request multiple times, that should be equivalent to a single request invocation.

When we wish to change a single resource that is already in the resources collection, we utilise the PUT method.

What is Post

This method is used to create a new resource. It’s commonly used when submitting a completed web form or uploading a file. This method requests the server to accept the entity which is enclosed in the request.

You can not cache POST method responses.

POST is NOT idempotent. So if we retry the request multiple times with same request body, You’ll make a new entry for each request.

POST method does not have resoiurce id with the URI

You can use CREATE query in POST.

Example of POST

Here is the webserver example of a PUT method:

http://dummy.restapiexample.com/api/v1/employee

Payload:

Responses:
HTTP/1.1 201 Created

What is PUT

This method is used to update an existing resource. The PUT method requests that the enclosed entity be stored under the supplied URI. If the URI belongs to an existing resource, it is updated; if it does not, the server can build the resource with that URI.

You can cache PUT method responses.

PUT is idempotent. So if we retry the request multiple times with same request body, You ll get same response.

PUT method syntax have resource id that’ll update /employee/{id}

You can use UPDATE query in PUT.

Example of PUT

Here is the webserver example of a PUT method:

HTTP POST http://www.www.dummy.restapiexample.com/employee/1

Payload:

Responses:
HTTP/1.1 200 Ok