Friday, 17 May 2024

Difference between HttpPut and HttpPost method

 Although technically, we can create and update resource with both Put and Post methods but as per standard we should use Post method to create a new resource while we should use Put method to update existing resource.

There are few differences between these two methods:

  1. While creating resource we don't have primary key of resource so in case of Post we don't have primary key in resource body but we have primary key of resource in case of Put.
  2. URI used for PUT method directly identify resource to update, while we will get a new URI for newly create resource by POST method.
  3. Most important difference between these two methods is PUT is idempotent means same request gives same response each time, but post can give different result. 



No comments:

Post a Comment

How to create and use middleware in asp.net core

Middleware is piece of code that's assembled into an app pipeline to handle requests and responses.  Each middleware component in the re...