Skip to content

0.1.HTTP

βš™οΈ What Is HTTP?

HTTP stands for HyperText Transfer Protocol.\ It is a TCP-based protocol used for transferring data between websites and applications.

  • The default protocol for web pages.

  • It typically runs on Port 80 (though this can be changed in the server settings).

  • It’s used for communication between Web Applications and Mobile Applications.

The communication happens between a Client (the user or browser) and a Server,\ through Requests and Responses.


πŸ”— What Is a URL and What Does It Contain?

URL stands for Uniform Resource Locator β€”\ it’s the address or link used to access a specific web page.

Example πŸ‘‡

Scheme       Host                Directory         Parameters
|             |                      |                   |
|             |                      |                   |
http://image.google.com:80/Secrets/index.php?id=13&message=Hello#top
              |             |             |                        |
     Second-Level Domain   Port          File                   Fragment
Part Description
Scheme The protocol type (e.g., http or https).
Host The website’s domain name or address.
Port The port used for the connection (default: 80 or 443).
Directory / File Path The internal path on the server to access a page or file.
Parameters Data values sent to the server (e.g., ?id=13).
Fragment A specific section on a page, indicated by #.

πŸ” HTTP vs HTTPS

In HTTP, all data is transmitted in plain text,\ which means it can be intercepted or read β€” for example, through a Man-in-the-Middle (MITM) attack.

This issue was solved with HTTPS,\ the secure version of HTTP that adds encryption via SSL/TLS.

Protocol Default Port Security
HTTP 80 ❌ Unencrypted
HTTPS 443 βœ… Encrypted and secure

πŸ“Š Main Difference: The presence (or absence) of encryption:


πŸ“© Components of an HTTP Request

An HTTP Request is what the client sends to the server.\ It consists of the following parts:

  1. Method – The type of operation (e.g., GET, POST, etc.)

  2. Path – The requested path on the server

  3. HTTP Version – The version of the HTTP protocol

  4. Headers – Additional information such as content type or browser details

  5. Body – Contains the data (used in methods like POST)

🧾 Example of an HTTP Request:

GET /index.html HTTP/1.1
Host: www.example.com
User-Agent: Mozilla/5.0
Accept-Language: en-US
Connection: keep-alive

πŸ“€ Components of an HTTP Response

An HTTP Response is what the server sends back to the client.\ It contains:

  1. Status Line – Includes the status code and message (e.g., 200 OK)

  2. Headers – Provide details about the server or file

  3. Body – Contains the actual data or webpage content

🧾 Example of an HTTP Response:

HTTP/1.1 200 OK
Date: Sun, 12 Oct 2025 20:00:00 GMT
Server: Apache/2.4.52
Content-Type: text/html
Content-Length: 1024

<html>
  <body>
    <h1>Welcome to Example Website</h1>
  </body>
</html>

🧱 Types of HTTP Headers

πŸ“© Request Headers

Header Name Description
Host Contains the IP or domain of the target server.
User-Agent Contains information about the client device or browser.
Connection Specifies whether to keep the connection alive after the request.
Referer The page from which the request originated.
Accept-Language The languages supported by the client.
Accept-Encoding Supported encoding/compression types.
Accept The data types the client accepts from the server.
Cookie Contains session or authentication data.
Content-Length The size of the request body data.
Content-Type The format of the request body (e.g., application/json).

πŸ“€ Response Headers

Header Name Description
Date The date and time the response was sent.
Location Used for redirects.
Set-Cookie Used to create or update cookies.
Server Contains information about the web server.

🧭 HTTP Methods

Method Description
GET Retrieves data from the server β€” no body (data in URL).
POST Sends data to the server (e.g., forms or files) via the body.
HEAD Similar to GET but without a body, used for validation.
OPTIONS Lists the allowed HTTP methods on the server.
PUT Creates or replaces existing data.
PATCH Updates part of an existing resource.
DELETE Deletes data from the server.

πŸ”Έ Common usage:

  • GET and POST β†’ Used in web applications.

  • PUT, PATCH, and DELETE β†’ Common in APIs.


πŸ“Š HTTP Response Codes

Category Meaning
1xx Informational or processing status.
2xx Success responses.
3xx Redirection responses.
4xx Client-side errors.
5xx Server-side errors.

Most Common Status Codes:

Code Meaning
200 OK Request succeeded.
302 Found Resource found (redirect).
400 Bad Request Invalid request syntax.
403 Forbidden Access denied – no permission.
404 Not Found Resource not found.
500 Internal Server Error Server encountered an internal issue.