# What is HTTP?

> The language browsers and servers use to talk to each other.

Source: https://aminbytes.dev/bytes/http/basics/what-is-http/


**HTTP** (HyperText Transfer Protocol) (Side note: Tim Berners-Lee designed the first version at CERN around 1990, together with HTML and the very first web browser.) is a set of rules for how a *client* asks for something and how a *server* answers.

- The **client** is usually your browser, but it can be `curl`, a mobile app or another server.
- The **server** is a program waiting for requests, for example the one behind `example.com`.

## It's just text

An HTTP/1.1 message is plain text. This is a real request a browser could send:

```http
GET /index.html HTTP/1.1
Host: example.com
Accept: text/html
```

And a possible answer:

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

<html><body><h1>Hello!</h1></body></html>
```

That's the whole idea: the client sends a request, the server sends one response back.

> [!NOTE]
> Newer versions (HTTP/2 and HTTP/3) send the same information in a compact binary form for speed. The *meaning* is identical, so everything you learn here still applies.

## See it yourself

`curl -v` prints the request it sends (lines starting with `>`) and the response it receives (lines starting with `<`):

```bash
curl -v https://example.com
```

```text
> GET / HTTP/2
> Host: example.com
> User-Agent: curl/8.7.1
> Accept: */*
>
< HTTP/2 200
< content-type: text/html
< content-length: 1256
...
```

## Stateless

HTTP is **stateless**: each request stands on its own, and the server doesn't remember the previous one. Logins and shopping carts work because the client sends something with *every* request (like a cookie) that lets the server recognize it. We'll see how in [Request headers](../../requests/request-headers/).


## Byte check

1. What does it mean that HTTP is **stateless**?
   - The server remembers every client between requests
   - **Each request stands on its own; the server doesn't remember the previous one** (correct)
   - A request can only be sent once
   That's why the client sends something like a cookie with *every* request, so the server can recognize it again.

2. In `curl -v` output, what do the lines starting with `<` show?
   - The request curl sends
   - **The response curl receives** (correct)
   - Errors and warnings
   `>` is what curl sends, `<` is what comes back from the server.

3. HTTP/2 and HTTP/3 send messages in binary. What changes about their meaning?
   - **Nothing: same methods, headers and status codes** (correct)
   - Headers aren't used anymore
   - They only work for images and video
   Only the encoding on the wire changes, for speed. Everything you learn with HTTP/1.1 still applies.


