kupendra pola
kupendra pola

Reputation: 97

What is the use of all GET, PUT, DELETE when anything can be done by POST in the most secured way of communication in REST API calls

I read a lot about each and every function of those mentioned in the title, But I always have doubt that what is the primary use of all individual functions. Can someone explain to me in detail? Thank you.

Upvotes: 0

Views: 57

Answers (2)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57204

What is the use of all GET, PUT, DELETE when anything can be done by POST

This is a pretty important question.

Note that, historically, SOAP essentially did everything by POST; effectively reducing HTTP from an application protocol to a transport protocol.

The big advantage of GET/PUT/DELETE is that the additional semantics that they promise (meaning, the semantics that are part of the uniform interface agreed to by all resources) allow us to build general purpose components that can do interesting things with the meta data alone, without needing to understand anything specific about the body of the message.

The most important of these is GET, which promises that the action of the request is safe. What this means is that, for any resource in the world, we can just try a GET request to "see what happens".

In other words, because GET is safe, we can have web crawlers, and automated document indexing, and eventually Google.

(Another example - today, I can send you a bare URI, like https://www.google.com and it "just works" because GET is understood uniformly, and does not require that we share any further details about a payload or metadata.)

Similarly, PUT and DELETE have additional semantic constraints that allow general purpose components to do interesting things like automatically retry lost requests when the network is unreliable.

POST, however, is effectively unconstrained, and this greatly restricts the actions of general purpose components.

That doesn't mean that POST is the wrong choice; if the semantics of a request aren't worth standardizing, then POST is fine.

Upvotes: 2

Gayathri
Gayathri

Reputation: 1896

In API perspective,

GET - It is to retrieve record/data from a source. API would need no data from client/UI to retrieve all records , or would need query param / path param to filter records based on what is required - either record with a particular ID or other properties.

POST - it is to store a new record at a source . API would get that record from client/UI through request body and store it.

PUT - it is to update an existing record at a source . API would receive updated record along with Id and update it with existing record whose id match with one passed from UI.

DELETE - it is to delete a record present in source. UI would send nothing to delete whole all records at source or send id to remove a particular record.

Source refers to any database.

Upvotes: 1

Related Questions