What are the HTTP request methods, and what is the difference between them?

Asked

Viewed 33,382 times

40

What are the HTTP request methods, among which are GET, POST and DELETE? What to use each of them, and what is the difference between them?

3 answers

48


  • GET: Requires a representation of the specified resource (The same resource can have multiple representations, for example services that return XML and JSON).
  • HEAD: Returns the headers of a response (without the body containing the resource)
  • POST: Sends an entity and requests that the server accepts it as a subordinate to the resource identified by the URI.
  • PUT: Requires an entity to be stored under the given URI. If the URI refers to a resource that already exists, it is modified; if the URI does not point to an existing resource, then the server can create the resource with that URI.
  • DELETE: Deletes the specified resource.
  • TRACE: Echoes back the request received for the client to see if there have been changes and additions made by intermediary servers.
  • OPTIONS: Returns the HTTP methods the server supports for the specified URL.
  • CONNECT: Converts the connection request to a transparent TCP/IP tunnel, usually to facilitate encrypted SSL (HTTPS) communication through an unencrypted HTTP proxy.
  • PATCH: Used to apply partial modifications to a resource.

Source: Wikipedia - Hypertext Transfer Protocol

  • Wow, HEAD was new to me. Most programmers don’t even care about these other methods, do they? Would it be valid to ask for examples of uses of these other methods, at least a description?

  • 1

    The latter two are more obscure methods. The trace also not so much used (more to diagnose problems in the middle of the way). GET and POST are trivial, and the rest are employed in Apis REST.

  • 2

    About asking for examples, I think it is valid within a more specific context (like "when should I use POST vs PUT?"), the community tends not to like wide questions very much (see the vote for this question to be closed).

  • 2

    There are also method extensions, which you can use - and although they are not "official" it depends only on the server to have the interpretation of the method, for example MEU-METODO do whatever I want on the server side.

  • An example of extension are the methods of Webdav.

  • It says on the wiki that it’s a protocol... it’s also an HTTP request method?

  • It’s a protocol that extends HTTP with a few more methods that only make sense for the protocol itself (exposing a kind of file repository through HTTP).

Show 2 more comments

5

Basically, if that’s what I understood, there are 8 types of methods of which:

GET, POST, DELETE, PUT, CONNECT, HEAD, TRACE, OPTIONS.

GET: Method that requests some resource or object from the server

HEAD: Requests information for a particular object without it being sent to the customer only to test the validity of the last access.

POST: Method used to send file/data or HTML form to the server.

OPTIONS: Through this method the client obtains the server properties.

DELETE: Informs through the URL the object to be deleted.

TRACE: To send a loopback message for testing.

PUT: Accepts to create or modify some server object.

CONNECT: Communicate with Proxy Servers.

Sources: http://www.vivaolinux.com.br/artigo/Um-pouco-do-protocolo-HTTP?pagina=4

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

1

GET, POST, PUT, DELETE are widely used in web projects API and represent the operations CRUD commonly used in databases.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.