Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
It is said that HTTPPUT Request updates the Object at Specific URI, but same thing we can achieve by HTTPPOST Request( WEBAPI .Net ) when to use HTTPPOST and When HTTPPUT.

What I have tried:

I created both HTTPPOST and HTTPPUT method in my APIController inherited class .And update with the same
Httppost Method.I am not getting why we need HTTPPUT when HTTPPOST is there or it is just to mention that we are updatng something that already exist.
Posted
Updated 30-May-16 2:39am
v2

In this article of mine, ASP.NET 5 Web API RESTful CRUDs and Windows 10 native application[^], I have talked about the HTTP verbs, POST and PUT. The problem is not with using which one, the problem is how to use the HTTP verbs in a way that they are meant to be used.

Using bad practices, I can upload something, update something or even create a new record all using the GET method HTTP request. I can pass the data which is to be saved as a query string and there, it is saved. That is not the good way of using the HTTP verbs when you are going to publish the API someday for public. That is why, you should always go and read the actual documentations before doing something.

Anyways, the HTTP verbs are used as:

1. HTTP GET: For requesting to get the resource at that URI.
2. HTTP DELETE: For requesting to delete the resource at that URI.
3. HTTP POST: For requesting to upload and save the data being uploaded to the data. Server then stores the entity and provides a new URI for that resource.
4. HTTP PUT: Same as POST but with a condition that it checks if that resources is already saved. If that resource is available then it simply updates.

These are the differences in the HTTP verbs that everyone should know and should write their web APIs using HTTP as protocol, accordingly.

For more on this, please refer to the following documents.

Hypertext Transfer Protocol - Wikipedia, the free encyclopedia[^]
HTTP Methods[^]
HttpVerbs Enumeration (System.Web.Mvc)[^] (For understanding only)
 
Share this answer
 
PUT is idempotent, so if you PUT an object twice, it has no effect. This is a nice property, so I would use PUT when possible.

Both method could be used, but you need to justify.

You could refer following thread;

http - PUT vs POST in REST - Stack Overflow[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900