Hypertext Transfer Protocol (HTTP)
Hypertext Transfer Protocol (HTTP) is a stateless protocol built on top of TCP.
- The usage of cookies developed later on to serve as state
- Handles requests and responses between a client and a server
- Every HTTP request (sent by client) and response (sent by server) consists of a header and a body
- Could only be sent as plaintext until HTTPS was introduced
- Types of HTTP headers: General, Response, Request
Components
- Method :
GET,POST,PUT,DELETE - Host :
www.example.com - Path :
/api/connect - Version :
HTTP/2 - Headers :
Content-Type application/json,Authorization: Basic Ezg6nnYnkTkk92kx - Query :
?q=my+search+term - Body :
{"q": "my search term"}
HTTP Routes
An http route is a mapping between a path like /api/connect and a handler
function that processes requests to that path. Routes define how the server
should respond to requests based on the path and the http method.
Example: A route for path /users/{id} triggers a function to retrieve user
information based on the user ID.
Main HTTP methods:
GET: Retrieve data from server, e.g. an HTML documentPOST: Submit data to server, e.g. an HTML formPUT: Update data already on the serverDELETE: Deletes data from the server
HTTP status codes:
- 1xx: Informational
- 2xx: Success
- 3xx: Redirect
- 4xx: Client Error
- 5xx: Server Error