![]() ![]() PUT is another HTTP method used to create a new resource at a specified URI or to update an existing resource. POST method is non-idempotent and is cacheable. Due to this reason, POST methond is not idempotent and unsafe. If you do the same request 2 times, 2 resources are created. "blog_post": "Confused whether to use PUT or PATCH or POST.", Lets look at this example: When you POST the following payload to the url On successful creation, return HTTP status 201, returning a Location header with a link to the newly-created resource. Since REST doesnt have a standard set of rules, some APIs use POST to update a resource as well. POST method should ideally be used only to create new resources. POST is a HTTP method used to create a new resource in a collection of resources. ![]() Now that we have an idea about idempotency, lets understand POST, PUT and PATCH and where does the confusion arise. HTTP request methods or ‘verbs’ equivalent to the CRUD, but they are not the same and serve different purpose While the returned value can vary with updates to the post, the content format is always same. No matter how many times it is called the same blog post is returned (content can vary) in the same format. For example, the GET method requests a certain blog post. To simply put, idempotency can be described as an API call when done multiple times provides the same result. Idempotence is the property of certain operations in mathematics and computer science, that can be applied multiple times without changing the result beyond the initial application. Before we understand the difference between PUT vs PATCH vs POST, first we need to understand Idempotency. Confused whether to use PUT or PATCH or POST in your API? Don’t worry you are not alone and this is a common confusion which happens to most of us or to all of us at some point while developing our API. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |