- Home
- API Design
- What is the difference between ...
PUT and POST requests have lots of similarities certainly when making an HTTP request. PUT and POST requests have a strong connection with HTTP. This article includes some major differences between PUT and POST requests.
What is PUT Method?
PUT is a request method supported by HTTP used by the World Wide Web, used to modify and update a resource.
Syntax
PUT /blogs/{blog-id}
Example
Here is an example of a PUT method:
- HTTP PUT http://www.blog.com/users/123
- HTTP PUT http://www.blog.com/users/123/accounts/567
What is POST Method?
POST method is used to create a resource, or overwrite it. The HTTP standard says that a POST request should be used when attempting to create a new resource representation. The POST request’s body contains the suggested state representation of the new resource to be added to the server.
Syntax
POST /blogs
Example
Here is an example of a POST method:
- HTTP POST http://www.blog.com/users
- HTTP POST http://www.blog.com/users/123/accounts
Difference between PUT and POST methods
PUT | POST |
This method is idempotent. In this method, if we send retry a request multiple times, that should be equivalent to a single request modification. | This method is not idempotent. In this method, if we retry the request N times, we will end up having N resources with N different URIs created on the server. |
The PUT method is used to modify a single resource. | The POST method is used to add a child resource. |
The PUT method is typically used for UPDATE operations. | POST method is generally used for CREATE operations. |
In the PUT method, the client decides which URI resource should have. | In the POST method, the server decides which URI resource should have. |
If you send the same request multiple times, the result will remain the same. | If you send the same POST request more than one time, you will receive different results. |
PUT works as specific. | POST work as abstract. |
Advantages of the PUT Method
- You can create a resource multiple times as you like.
- Creating a resource with the PUT method is very easy.
- It helps you to store the supplied entity under the supplied URI.
- It can identify the entity enclosed with the request.
Advantages of the POST Method
- You can keep the data private.
- The POST method can be used to send binary as well as ASCII data.
- It is a secure method as its requests do not remain in browser history.
- It is very useful when you do not know the URL to keep any resource.