HTTP, HTTPS and REST
Overview
HTTP is the language web clients and servers use to ask for things and answer. HTTPS makes that conversation private, and REST is a common style for designing APIs on top of it.
Detailed Notes
What is HTTP
HTTP (HyperText Transfer Protocol) is the set of rules for how a client sends a request and how a server replies, usually running on top of TCP. Every web page, mobile app call and API call you make uses it.
An API (Application Programming Interface) is a defined way for one program to ask another to do something, for example "give me the profile of user 42".
An HTTP request has:
- A method: what you want to do.
- A URL path: which thing you mean, like
/users/42. - Headers: extra details (who you are, what format you accept).
- An optional body: data you send, often JSON.
The response has a status code, headers and a body.
The problem it solves
Clients and servers are written by different people in different languages. They need one shared, simple convention so that any client can talk to any server. HTTP is that convention. HTTPS adds a second need: anyone on the path (shared Wi-Fi, routers) could read or alter plain HTTP traffic, so we need privacy and proof that we are talking to the real server.
How it works
Common methods
GET: read something. Should not change data.POST: create something.PUT/PATCH: replace / partly update something.DELETE: remove something.
Status codes are grouped by their first digit:
2xxsuccess (200 OK,201 Created)3xxredirect4xxthe client made a mistake (400bad request,401not logged in,404not found,429too many requests)5xxthe server failed (500,503unavailable)
HTTPS is HTTP wrapped in TLS (Transport Layer Security). Before any data is sent, the server shows a certificate proving its identity, and both sides agree on secret keys. After that everything is encrypted (scrambled so only the two ends can read it). The padlock in your browser means this worked.
REST (Representational State Transfer) is a style for APIs built on HTTP:
- Things are resources named by URLs, e.g.
/orders/17. - You use the HTTP methods as the verbs (
GET /orders/17,DELETE /orders/17). - Servers are stateless: each request carries everything needed to handle it, and the server does not remember the previous request. This lets any server answer any request, which becomes very useful when you run many servers.
- Data usually travels as JSON, a simple text format of names and values.
A simple example
Fetching an order:
GET /orders/17 HTTP/1.1
Host: shop.example.com
Authorization: Bearer <token>
The server replies (the token in the header is a secret string, like a ticket, that proves who you are):
HTTP/1.1 200 OK
Content-Type: application/json
{ "id": 17, "status": "shipped", "total": 42.50 }
If order 999 does not exist, the reply is 404 Not Found. If the token is missing, it is 401.
System design example
A mobile shop app calls https://api.shop.example.com. The connection is TCP plus TLS on port 443. Requests like POST /orders create orders; GET /orders/17 reads one.
Because the API is stateless, the company can run ten identical servers and any of them can answer any request; the user's login is proven by a token sent with each call rather than remembered by one particular server. Good API habits include using correct status codes, so clients know whether to fix their request (4xx) or retry later (5xx).
One more design point: GET should be safe to repeat. If a request times out, a client can just try again. Repeating a POST might create a duplicate order, so designers add extra protection for that (covered later).
Summary
- HTTP defines how clients send requests (method, path, headers, body) and servers reply (status, body).
- Status codes: 2xx success, 4xx client error, 5xx server error.
- HTTPS = HTTP + TLS: encrypted and the server's identity is verified.
- REST uses URLs for resources and HTTP methods as verbs; it is stateless.
- Stateless servers make it easy to add more servers later.
Architecture Diagram
A REST request travels over TCP and TLS on port 443.
- 1The client opens a TCP connection and completes the TLS handshake.
- 2It sends GET /orders/17 with a token in the headers.
- 3The server reads the order from the database.
- 4It replies 200 OK with the order as JSON.
Common Interview Questions
Chapter quiz
Network Essentials · 5 questions
1.What does a port identify?
2.Which protocol is best for a live video call where late data is useless?
3.A client gets a 404 response. What happened?
4.Why are stateless servers useful?
5.What does TLS provide in HTTPS?
0 of 5 answered
Finished this lesson?
0 of 91 lessons done · 0% of the course

