andersch.dev

<2022-05-04 Wed>
[ web ]

Hypertext Transfer Protocol (HTTP)

Hypertext Transfer Protocol (HTTP) is a stateless protocol built on top of TCP.

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 document
  • POST: Submit data to server, e.g. an HTML form
  • PUT: Update data already on the server
  • DELETE: Deletes data from the server

HTTP status codes:

  • 1xx: Informational
  • 2xx: Success
  • 3xx: Redirect
  • 4xx: Client Error
  • 5xx: Server Error