HowToTellAChild
HowToTellAChild

Reputation: 729

Base understanding of using HTTP methods like GET, POST etc

I'm thinking to understand the base use of HTTP verbs GET, POST etc... I read these articles, but it is not so clear for me yet:

In a RESTful application, how do we differentiate between an "action" and an HTTP verb (GET, POST, PUT, DELETE)?

Why use HTTP verbs?

Use of HTTP RESTful methods GET/POST/etc. Are they superfluous?

I just don't see the propose to add an qualifier (as I know, GET, POST etc... is an qualifier) for a method calling. Why don't just call a method through URL (like server.domain/methods/addnewproduct), and the server side will decide what to do? I understand when to use GET, POST, UPDATE etc... (CRUD procedure bla-bla-bla) I just don't see why to implement these verbs for qualifying remote method calling. I read that many time, it is because these are safe methods, but why are these methods safe?

Upvotes: 0

Views: 87

Answers (1)

Quentin
Quentin

Reputation: 943098

Why don't just call a method through URL (like server.domain/methods/addnewproduct), and the server side will decide what to do?

The URL identifies a thing. The HTTP METHOD describes how you want to interact with it.

http://example.com/HowToTellForAChild could represent you.

Someone might want to GET the information about you, or they might want to PUT new information about you on the server.

They are still interacting with the same entity, but in different ways.

http://example.com/HowToTellForAChild/GET would mix up the identification and the type of interaction into one thing. At best that is just confusing.


I read that many time, it is because these are safe methods, but why are these methods safe?

See the specification:

These methods ought to be considered "safe". This allows user agents to represent other methods, such as POST, PUT and DELETE, in a special way, so that the user is made aware of the fact that a possibly unsafe action is being requested.

For a practical example:

Say you are ordering a doll house over the Internet. You submit a form. It triggers a POST request.

If you then press the Refresh button, the browser recognises that you just make a POST request and asks you if you are sure you want to make the request again.

This stops you ordering a second doll house by accident.

(Although see the PRG pattern).

Upvotes: 1

Related Questions