Sobes.tech
Intern

What is HTTP?

sobes.tech AI

Answer from AI

HTTP (Hypertext Transfer Protocol) is an application layer protocol for data transfer between a client (browser) and a server. It is used for interaction on the World Wide Web.

Main characteristics:

  • Request-Response Protocol: The client sends a request to the server, the server processes it and sends a response.
  • Stateless: The server does not retain information about previous client requests. Each interaction is independent. Mechanisms like cookies and sessions are used to maintain state.
  • Text-based Protocol: HTTP messages contain header fields and optionally a message body, which are represented in text format.
  • Uses TCP: HTTP typically operates over TCP/IP to ensure reliable data delivery.

HTTP message structure:

  • Request line (for requests) / Status line (for responses)
  • Headers
  • Blank line (separates headers from the body)
  • Message body

Examples of common request methods:

  • GET: Request data from a specified resource.
  • POST: Send data to the server to create or update a resource.
  • PUT: Replace all current representations of the target resource with the request body.
  • DELETE: Remove the specified resource.
  • PATCH: Partially update a resource.
  • HEAD: Request headers of a resource without obtaining its body.

Examples of response status codes:

Code Category Description
1xx Informational Request received, continuing.
2xx Success The request was successfully processed.
3xx Redirection Further action required.
4xx Client Error Error in the request.
5xx Server Error Error on the server side.

Example of a simple HTTP request:

GET /index.html HTTP/1.1
Host: example.com
User-Agent: MyBrowser/1.0
Accept: text/html

Example of a simple HTTP response:

HTTP/1.1 200 OK
Content-Type: text/html; charset=utf-8
Content-Length: 1234

<!DOCTYPE html>
<html>
<head><title>Example</title></head>
<body>
<h1>This is a header</h1>
</body>
</html>