mewi
mewi

Reputation: 569

Purpose of the different HTTP-Methods?

What's the purpose of the HTTP-methods GET, POST, PUT, DELETE, HEAD etc.

Is it just a convention to indicate, what I'm intending to do? Or is it, that certain HTTP-features are only available if I use a specific method?

Upvotes: 0

Views: 374

Answers (2)

VoiceOfUnreason
VoiceOfUnreason

Reputation: 57194

REST enables intermediate processing by constraining messages to be self-descriptive: interaction is stateless between requests, standard methods and media types are used to indicate semantics and exchange information, and responses explicitly indicate cacheability. -- Fielding, 2000

The important idea here is that the self descriptive messages of REST communicate semantics in such a way that general purpose components can understand them and do something useful with that information.

For instance, if we know that the semantics of a message are idempotent, we can automatically resend that message when a response is lost.

We know that if the semantics of a message are safe, then we can send that request purely speculatively. This not only allows optimizations like pre-fetching content, but it also means that we can safely crawl the web, looking for interesting documents.

Because the message semantics are visible in readily standardizable forms, we can drop in general purpose, off the shelf components, and everything just works.


SOAP is an example of message passing that did not have standardized semantics. Messages were XML documents that could only be interpreted correctly by components familiar with that specific schema (usually via the WSDL).

On the web, that meant that, regardless of meaning, every request was sent via POST. What that does, in effect, is reduce HTTP from an application protocol to a transport protocol. And a lot of the power of the web goes away when you do that.

Upvotes: 1

Java Boss
Java Boss

Reputation: 398

GET requests:

  • GET requests can be cached
  • GET requests remain in the browser history
  • GET requests can be bookmarked
  • GET requests should never be used when dealing with sensitive data
  • GET requests have length restrictions
  • GET requests are only used to request data (not modify)

POST requests:

  • POST requests are never cached

  • POST requests do not remain in the browser history

  • POST requests cannot be bookmarked

  • POST requests have no restrictions on data length

now I hope you understood the difference between GET and POST. In similar ways, every method has different purpose.

Upvotes: 1

Related Questions