When to use PUT or POST Lets compares them for better understanding.
PUT | POST |
---|---|
Use PUT when you want to update a resource completely through a specific resource Id. For instance, if you know that an article resides at Id 1 then you can use PUT. | Use POST when you do not know the actual resource location, for instance, when you want to add a new resource then you can POST. |
PUT method is idempotent. So if you send retry a request multiple times, that should be equivalent to single request modification. | 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 server. |
Always use PUT for UPDATE operations. |
Always use POST for CREATE operations. |
NOTE-PUT and POST are both unsafe methods. However, PUT is idempotent, while POST is not.
What is idempotent method.