HTTP & REST
The language clients and servers use to communicate
Introduction
When you open an app on your phone, it talks to a server somewhere in the world. But how do two programs — often written in different languages, running on different hardware — understand each other? They use a common language called HTTP.
HTTP (HyperText Transfer Protocol) is the foundation of data communication on the web. Every time your browser loads a page or your app fetches data, it sends an HTTP request and receives an HTTP response. Think of it as the postal service of the internet — it defines exactly how to address a message, what format it should be in, and how the reply comes back.
REST (Representational State Transfer) is a popular design pattern for building APIs that use HTTP. A RESTful API organises resources (like users, posts, or products) into URLs and uses HTTP methods as verbs to manipulate them. It is the most common way modern web and mobile apps talk to servers.
How It Works
HTTP is a request-response protocol. A client (your app or browser) sends an HTTP request to a server. The server processes it and sends back an HTTP response with a status code and data. REST uses this same protocol but adds conventions: each URL represents a resource, and the HTTP method tells the server what action to perform.
Restaurant Analogy
Imagine you are at a restaurant. GET is like looking at the menu — you are just reading what is available. POST is telling the waiter you want to order a new dish that is not on the menu yet. PUT is asking to modify your order (e.g. "make it medium rare instead of well done"). DELETE is cancelling an item from your order. The waiter (server) always responds with a status: "right away" (200), "we do not have that" (404), or "the kitchen is on fire" (500).
Deeper Dive
REST APIs use these four main HTTP methods as verbs. Each one has a specific meaning:
GET
Retrieve data. Read a resource. Safe and idempotent — calling it multiple times does not change anything.
Example: GET /api/users
POST
Create a new resource. Sends data to the server to create something new. Not idempotent — each call creates a new entry.
Example: POST /api/users
PUT
Update an existing resource. Replaces the entire resource with new data. Idempotent — same call multiple times has the same effect.
Example: PUT /api/users/1
DELETE
Remove a resource. Deletes the specified resource from the server. Idempotent — deleting twice is the same as deleting once.
Example: DELETE /api/users/1
HTTP Status Codes
Every HTTP response includes a status code that tells the client what happened. Here are the most common ones:
200 OK
The request succeeded. Data is returned in the response body.
201 Created
A new resource was created (typically after a POST request).
400 Bad Request
The server could not understand the request due to invalid syntax or missing data.
404 Not Found
The requested resource does not exist on the server.
500 Server Error
Something went wrong on the server. The client cannot fix this — the server needs debugging.
Key Insight
REST is not a standard or a protocol — it is an architectural style. When an API is "RESTful," it follows a set of conventions: resources are identified by URLs, and actions are performed using standard HTTP methods. This simplicity is why REST has become the dominant API design pattern on the web.
Advanced
At a deeper level, http & rest involves rules and patterns that engineers use worldwide. HTTP follows standards so different brands and devices can still work together. That is why your phone, school laptop, and game console can all connect to the same network or use the same apps.
HTTPS does not happen in a straight line. Systems often use backup paths, error checking, and retries so information arrives correctly. When something fails, smart GET design helps the system recover instead of shutting down completely.
Scientists and engineers keep improving these systems every year — making them faster, safer, and more energy-efficient. The ideas you learn in this chapter are the same building blocks used in real data centers, robots, apps, and websites around the world.
Vocabulary Table
| Term | Definition |
|---|---|
| HTTP | HyperText Transfer Protocol — the foundation protocol for data communication on the web |
| HTTPS | HTTP Secure — HTTP encrypted with TLS/SSL for secure communication |
| GET | HTTP method used to retrieve data from a server |
| POST | HTTP method used to send data and create a new resource |
| PUT | HTTP method used to update an existing resource |
| DELETE | HTTP method used to remove a resource |
| REST | Representational State Transfer — an architectural style for designing networked applications |
| Status Code | A three-digit number in an HTTP response that indicates the result of the request |
| URL | Uniform Resource Locator — the address used to access a resource on the web |
| Endpoint | A specific URL in an API that represents a resource or collection of resources |
Fun Facts
HTTP was invented by Tim Berners-Lee in 1989. The very first HTTP request was made to fetch a document at CERN — and it returned a 404 error because the page was not ready yet.
There are over 60 standard HTTP status codes, but most developers only use about 10 regularly. The most famous is 404 Not Found.
Roy Fielding coined the term REST in his 2000 PhD dissertation. His goal was to define a set of constraints that make web services scalable and predictable.
HTTP/3, the latest version, uses QUIC (a UDP-based protocol) instead of TCP. This makes connections faster, especially on mobile networks with packet loss.
The 418 status code ("I am a teapot") is a real joke HTTP status defined in 1998 as an April Fools' RFC. Some APIs still use it for fun.
Interactive Diagram
Launch the interactive diagram to see HTTP methods and REST in action.
Open Interactive DiagramThe interactive diagram for this chapter demonstrates HTTP and REST. It shows HTTP methods (GET, POST, PUT, DELETE) being used to interact with a REST API.
What to explore:
- click different HTTP method buttons; watch the request being formed and sent; see the status code and response
- REST APIs use standard HTTP methods — GET to read, POST to create, PUT to update, and DELETE to remove data
Knowledge Check
1. Which HTTP method would you use to retrieve a list of users from an API?
Answer: GET
2. What does the HTTP status code 404 mean?
Answer: The requested resource was not found
3. What does REST stand for?
Answer: Representational State Transfer
