2.3. HTTP Method

  • GET - Read

  • POST - Create

  • PUT - Update/Replace

  • PATCH - Partial Update/Modify

  • DELETE - Delete

  • HEAD - Show Headers

  • CONNECT - Connect

  • OPTIONS - Show HTTP Methods

  • TRACE - Show Trace

$ nc localhost 8000
GET / HTTP/1.1
Host: localhost:8000

2.3.1. GET

  • GET - Read

  • Retrieve data

  • No other effect

Requests using GET should only retrieve data and should have no other effect.

$ curl -X GET http://localhost:8000/

2.3.2. POST

  • POST - Create

  • Stores information on the server

  • Requires whole object

  • Assigns a new URI

The POST method requests that the server accept the entity enclosed in the request as a new subordinate of the web resource identified by the URI.

$ curl -X POST http://localhost:8000/

2.3.3. PUT

  • PUT - Update/Replace

  • Stores information on the server

  • Requires whole object

  • Reuse URI

The PUT method requests that the enclosed entity be stored under the supplied URI.

$ curl -X PUT http://localhost:8000/

2.3.4. PATCH

  • PATCH - Partial Update/Modify

  • Stores information on the server

  • Requires part of object

  • Reuse URI

The PATCH method applies partial modifications to a resource.

$ curl -X PATCH http://localhost:8000/

2.3.5. DELETE

  • DELETE - Delete

  • Removes information from the server

  • Requires URI

  • Discards URI

The DELETE method deletes the specified resource.

$ curl -X DELETE http://localhost:8000/

2.3.7. CONNECT

  • CONNECT - Connect

  • Request connection to a transparent TCP/IP tunnel

  • Used for SSL-encryption (HTTPS) through an unencrypted HTTP proxy

The CONNECT method converts the request connection to a transparent TCP/IP tunnel, usually to facilitate SSL-encrypted communication (HTTPS) through an unencrypted HTTP proxy.

$ curl -X CONNECT http://localhost:8000/

2.3.8. OPTIONS

  • OPTIONS - Show HTTP Methods

  • Returns HTTP methods for the specified URL

The OPTIONS method returns HTTP methods that the server supports for the specified URL.

$ curl -X OPTIONS http://localhost:8000/

2.3.9. TRACE

  • TRACE - Show Trace

  • Echoes the received request

  • Debug what changes have been made by intermediate servers

The TRACE method echoes the received request so that a client can see what (if any) changes or additions have been made by intermediate servers.

$ curl -X TRACE http://localhost:8000/

2.3.10. Match Block

  • HTTP Request

  • Match Block

  • 'GET /index.html HTTP/2.0'

>>> request = 'GET /index.html HTTP/2.0'
>>>
>>> match request.split():
...     case ['GET', uri, version]:     handle_get(uri)
...     case ['POST', uri, version]:    handle_post(uri)
...     case ['PUT', uri, version]:     handle_put(uri)
...     case ['DELETE', uri, version]:  handle_delete(uri)

2.3.11. Use Case - 0x01

$ curl -X GET http://localhost:8000/
$ curl -X POST http://localhost:8000/
$ curl -X PUT http://localhost:8000/
$ curl -X PATCH http://localhost:8000/
$ curl -X DELETE http://localhost:8000/
$ curl -X HEAD http://localhost:8000/
$ curl -X OPTIONS http://localhost:8000/
$ curl -X TRACE http://localhost:8000/