2.3. HTTP Method
GET
- ReadPOST
- CreatePUT
- Update/ReplacePATCH
- Partial Update/ModifyDELETE
- DeleteHEAD
- Show HeadersCONNECT
- ConnectOPTIONS
- Show HTTP MethodsTRACE
- Show Trace
$ nc localhost 8000
GET / HTTP/1.1
Host: localhost:8000
2.3.1. GET
GET
- ReadRetrieve 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
- CreateStores 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/ReplaceStores 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/ModifyStores 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
- DeleteRemoves information from the server
Requires URI
Discards URI
The DELETE method deletes the specified resource.
$ curl -X DELETE http://localhost:8000/
2.3.6. HEAD
HEAD
- Show HeadersIdentical to
GET
request without the response body
The HEAD method asks for a response identical to that of a GET request, but without the response body.
$ curl -X HEAD http://localhost:8000/
2.3.7. CONNECT
CONNECT
- ConnectRequest 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 MethodsReturns 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 TraceEchoes 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 - 1
$ 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/