What HTTP and REST are and how they work
HTTP (Hypertext Transfer Protocol) is an application-layer request–response protocol: the client sends a request for the resource identified by a URI, and the server sends back a response whose status code reports the result. REST is an architectural style for APIs on top of HTTP: every resource has its own address, and a standard method sets the action.
HTTP keeps no state between requests: the meaning of each request follows from the request itself and does not depend on which requests have passed over the same connection before it. Requests from one client can therefore be spread across servers and sent through shared proxies. Sessions on top of HTTP are built on cookies: the server issues a cookie in the Set-Cookie header field, and the browser returns it in Cookie.
Who takes part in the exchange
| Participant | What it does |
|---|---|
| Client (user agent) | Opens a connection and sends requests: a browser, curl, a mobile app, a crawler |
| Origin server | Stores the resource and answers a request for it with an authoritative response |
| Proxy | An intermediary chosen by the client: forwards requests, may cache and filter |
| Gateway, reverse proxy | Looks like the origin server to the client and passes requests to the servers behind it: balances load, caches |
| Tunnel | Forwards bytes between two connections without reading them: this is how TLS passes through a proxy |
| Cache | Stores responses and answers repeated requests itself, shortening the path to the server |
Message semantics are the same for every version of HTTP: the methods, status codes and header fields are defined by RFC 9110. The versions differ in how they carry the data. HTTP/1.1 and HTTP/2 run over TCP, and for https addresses inside TLS as well. HTTP/3 runs over QUIC — a transport on top of UDP with TLS 1.3 built in (details in the section “HTTP/1.1, HTTP/2 and HTTP/3”). Underneath them all lies IP.
http:// addresses there is no TLS layer above TCP; in QUIC, TLS 1.3 is always built in.What a REST API is
REST (Representational State Transfer) needs no commands of its own — the standard HTTP methods are enough: the resource is given by its address, the action by a method whose meaning is the same for every resource, the result by a status code. The meaning is set by the method, not by the words in the address: on a GET the client may expect that the resource will not change, whatever the URI says.
The HTTP standard sets no ready-made rules for REST, so every API describes its own resources — with documentation or an OpenAPI contract. How to choose addresses, status codes, pagination and versions — in the section “REST API design”.
How it differs from gRPC and GraphQL
| Aspect | REST | gRPC | GraphQL |
|---|---|---|---|
| Model and addresses | Resources, each with its own URI | Service methods (RPC), each with a fixed path | A graph of entities behind one address, usually /graphql |
| Transport | HTTP of any version | HTTP/2, streams in both directions at once | Most often HTTP: POST, and GET for reads as well |
| Data format | Any media type, for example JSON | Usually Protocol Buffers; clients are generated from the service description | JSON: a request document and variables; the response is data and errors |
| Errors | HTTP status codes and problem details | Its own set of error codes | A 2xx status code when the response has data, even with errors in errors |
Choose REST when an API has many different clients, browsers included: such an API relies on standard HTTP semantics that caches, proxies and any HTTP library understand. gRPC is designed for distributed systems with low latency and mobile clients: the service description sets the contract, and calls can stream in both directions; from a browser it works through gRPC-Web — details in the gRPC reference. GraphQL is the choice when a client works with a graph of related entities through a single address.
What to know in advance
- TCP connections, ports, name resolution — the “TCP/IP and DNS” reference
- What happens when a connection is made over
https— the “TLS and PKI” reference - The JSON format: the request and response bodies in the reference’s examples are written in it
Section sources
the section is written from these pages- Overview of HTTPdeveloper.mozilla.org/en-US/docs/Web/HTTP/Guides/Overview(opens in a new tab)
- RFC 9110: HTTP Semantics — 3. Terminology and Core Conceptsrfc-editor.org/rfc/rfc9110.html(opens in a new tab)
- Evolution of HTTPdeveloper.mozilla.org/en-US/docs/Web/HTTP/Guides/Evolution_of_HTTP(opens in a new tab)
- FAQ | gRPCgrpc.io/docs/what-is-grpc/faq/(opens in a new tab)
- Serving over HTTP | GraphQLgraphql.org/learn/serving-over-http/(opens in a new tab)