views:

509

answers:

5

HTTP defines eight methods (sometimes referred to as "verbs")

Can you help me find examples for each one so I can test and understand them better?

+1  A: 

I guess reading RFC 2616 explains all: http://www.faqs.org/rfcs/rfc2616.html

Arjan
+3  A: 

Try this: http://rest.blueoxen.net/cgi-bin/wiki.pl?HttpMethods

It also gives an overview of their properties.

Jaka Jančar
+1 The chart is great.
Gumbo
+2  A: 

You can experiment with the different HTTP methods using the cURL command line tool. For example:

curl --head http://www.google.co.uk

HTTP/1.1 200 OK
Cache-Control: private, max-age=0
Date: Sun, 19 Apr 2009 15:33:24 GMT
Expires: -1
Content-Type: text/html; charset=ISO-8859-1
Set-Cookie: PREF=ID=a2a414b9a84c8ffd:TM=1240155204:LM=1240155204:S=16kZnqzeSxIJT3jv; expires=Tue, 19-Apr-2011 15:33:24 GMT; path=/; domain=.google.co.uk
Server: gws
Transfer-Encoding: chunked
  • The -X option lets you specify an HTTP method other than GET.
John Topley
Good hint, +1. Note that not all browsers support all methods. That's why, for example, Ruby on Rails actually only uses GET and POST, and not PUT and DELETE. If curl does not support all methods, then one can even use telnet to manually invoke them: see for example http://tonycode.com/wiki/index.php?title=Making_HTTP_requests_via_telnet
Arjan
Agreed, I've done that with Telnet before.
John Topley
+5  A: 

First you should take a look into the HTTP 1.1 specification, especially the section method definitions.

  • OPTIONS Get information about how the server allows to communicate with.

    Request:

    OPTIONS * HTTP/1.1
    Host: example.com
    

    Response:

    HTTP/1.1 200 OK
    Date: …
    Allow: OPTIONS, GET, HEAD, POST, PUT, DELETE, TRACE
    Content-Length: 0
    
  • GET Retrieve a resource.

    Request:

    GET /foo/bar HTTP/1.1
    Host: example.com
    

    Response:

    HTTP/1.1 200 OK
    Date: …
    Content-Type: text/html;charset=utf-8
    Content-Length: 12345
     
    <!DOCTYPE …
    
  • HEAD Like GET, but returns just the HTTP header.

    Request:

    HEAD /foo/bar HTTP/1.1
    Host: example.com
    

    Response:

    HTTP/1.1 200 OK
    Date: …
    Content-Type: text/html;charset=utf-8
    Content-Length: 12345
    
  • POST Send data to the server.

    Request:

    POST /foo/bar HTTP/1.1
    Host: example.com
    Content-Type: application/x-www-form-urlencoded
     
    action=addentry&subject=Hello,%20World
    

    Response:

    HTTP/1.1 201 Created
    Date: …
    Content-Length: 0
    Location: http://example.com/foo/bar
    
  • PUT Create a new resource.

  • DELETE Delete an existing resource.

  • TRACE Return the request headers sent by the client.

    Request:

    TRACE /foo/bar HTTP/1.1
    Host: example.com
    

    Response:

    HTTP/1.1 200 OK
    Date: …
    Content-Length: 17
     
    Host: example.com
    

I don’t know exactly if these examples are correct. Feel free to correct them.

Gumbo
very good answer :)
dfa
and how to write a put method
Amr ElGarhy
Also how to test these methods? write them where to get the response?
Amr ElGarhy
@Amr ElGarhy: I’ve never used PUT myself. So I cannot give you an example for it.
Gumbo
Testing is covered in John Topley's answer. That is: for the client side. For the server side you'd need to specify what programming language you're about to use.
Arjan
Language is .Net
Amr ElGarhy
A: 

HI John,

You can test and learn about HTTP WEB Request using the next: http request testing tool I use it to send different http request and analyze the response

Michael