When you open a website or interact with an API, your browser or application communicates with a web server using HTTP (HyperText Transfer Protocol). Letβs break down how this communication works step by step.
πΉ 1. HTTP Requests
Every HTTP interaction starts with a request sent by the client (e.g., your browser).
π (a) Request Line
The first line of the request specifies:
- The method
- The resource
- The protocol version
Example:
GET /home.html HTTP/1.1
GET β HTTP method
/home.html β resource being requested
HTTP/1.1 β protocol version
π οΈ (b) Common HTTP Methods
GET β Request a resource from the server
POST β Send data to the server
PUT β Replace an existing resource
PATCH β Update part of a resource
DELETE β Remove a resource
π¬ (c) Request Headers
Headers provide extra information about the request.
Example:
Host: example.com
User-Agent: Mozilla/5.0
Accept: text/html
Accept-Language: en
Content-Type: application/json
Host β identifies the target server
User-Agent β tells the server which client is making the request
Accept β specifies which content types are acceptable in response
Accept-Language β preferred language
Content-Type β type of data being sent (e.g., JSON, HTML)
π¦ (d) Request Body
Often used with POST or PUT to send data:
POST /users HTTP/1.1
Host: example.com
Content-Type: application/json
{
"name": "Usama",
"age": 23
}
πΉ 2. HTTP Responses
Once the server processes the request, it replies with an HTTP response.
π·οΈ (a) Status Line
Example:
HTTP/1.1 200 OK
HTTP/1.1 β protocol version
200 β status code
OK β reason phrase
π (b) Common Status Codes
1xx Informational β Request received (e.g., 100 Continue)
2xx Success β Request succeeded (e.g., 200 OK, 201 Created)
3xx Redirection β Resource moved (e.g., 301 Moved Permanently, 302 Found)
4xx Client Error β Problem in request (e.g., 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found)
5xx Server Error β Problem on server side (e.g., 500 Internal Server Error, 503 Service Unavailable)
π (c) Response Headers
Provide metadata about the response:
Date: Tue, 10 Sep 2025 12:00:00 GMT
Server: Apache/2.4.1 (Linux)
Content-Type: text/html
Content-Length: 120
Date β when the response was generated
Server β server software details
Content-Type β type of returned content
Content-Length β size of the response body
π (d) Response Body
This is the actual content returned (HTML, JSON, images, etc.):
<html>
<head><title>Hello</title></head>
<body>Hello Usama!</body>
</html>
πΉ 3. Full Example: Request β Response Flow
Client Request
GET /index.html HTTP/1.1
Host: example.com
User-Agent: Chrome/120.0
Accept: text/html
Server Response
HTTP/1.1 200 OK
Date: Tue, 10 Sep 2025 12:00:00 GMT
Server: Apache/2.4.1 (Linux)
Content-Type: text/html
Content-Length: 120
<html>
<body>Hello World!</body>
</html>
β Summary
An HTTP Request = Method + Headers + (optional) Body
An HTTP Response = Status Line + Headers + Body
Status Codes quickly tell you whether a request was successful, redirected, invalid, or failed
Understanding this flow is essential for working with web development, APIs, and debugging client-server communication.
π‘ Now youβre ready to inspect, debug, and even build APIs with confidence!
Top comments (1)
This information I took in meta front end course available in Coursera