In this article, we will discuss about the PUT and POST requests in the Restful web services with relevant example.
Replaces all the representations of the member resource or create the member resource if it does not exist, with the representation in the request body.
PUT the method is idempotent. So if you send retry a request multiple times, that should be equivalent to single request modification.
Generally, in practice, always use
PUT for UPDATE operations.
Creates a member resource using the instructions in the request body. The URI of the created member resource is automatically assigned and returned in the response Location header field.
POST is NOT idempotent. So if you retry the request N times, you will end up having N resources with N different URIs created on the server.
POST for CREATE operations.
Finally we have discussed about the differences between PUT and POST request in the Restful web services. If you have any questions, feel free to ask in the comments.
When to use PUT request?
Use PUT for Update operations as it is idempotent.
When to use POST request?
User POST for Insert Operations.