Question
My question is what is the disadvantage/drawback(technical or design) If I continue to use POST method instead of DELETE/PUT for deleting/updating the resource in Rest ?
The POST
request is not Idempotent
but the DELETE
request is Idempotent
.
An idempotent HTTP method is a HTTP method that can be called many times without different outcomes
Idempotency
is important in building a fault-tolerant
API.
Let's suppose a client wants to update a resource through POST
. Since POST is not an idempotent method, calling it multiple times can result in wrong updates. What would happen if you sent out the POST request to the server, but you get a timeout? Did the resource actually get updated? Did the timeout happen when sending the request to the server, or when responding to the client? Can we safely retry again, or do we need to figure out first what happened with the resource? By using idempotent methods, we do not have to answer this question, but we can safely resend the request until we actually get a response back from the server.
So, if you use POST for deleting, there will be consequences.
When we use POST instead of Delete in our rest API then we are snatching power of Idempotency from client.That means,By using POST we are saying to our API user that this API can produce differnent result upon hitting multiple time.
In case of Timeout, API user have to enquiry for the resource which he had made a request to delete.Then if found,he has to made a call to POST API to delete it.
Where if same request is made using Delete method.Then we are assuring our API user that multiple calls to same method will return same result. Hence he can raise any number of request untill he gets successful deletion instead of Timeout without inquiry.
Note : Maintaining Idempotency is the duty of API maker.Just putting Delete method do not give Idempotency.
HTTP Method | Idempotent | Description | Example |
GET | Yes | Retrieves data from the server without changing its state. |
|
PUT | Yes | Replaces the current resource with the request payload. |
|
DELETE | Yes | Deletes the specified resource. |
|
HEAD | Yes | Retrieves headers for a resource, similar to GET but without the body. |
|
OPTIONS | Yes | Describes the communication options for the target resource. |
|
POST | No | Creates a new resource or causes a change in state on the server. Each identical request may create a new resource. |
|
PATCH | No | Applies partial modifications to a resource. |
|
Last updated