HTTP Protocol (HyperText Transfer Protocol)

Defines how clients (e.g., browsers) and servers communicate using a stateless request–response model. HTTP is an application-layer protocol that runs on top of TCP.

HTTP Communication Model

HTTP follows a simple cycle:

Client (Browser)

    ├── HTTP Request


Server

    ├── HTTP Response


Client receives data (HTML / JSON / etc.)

HTTP Request

A request is sent from the client to the server.

Structure:

  • Request Line
    • Method (GET, POST, PUT, DELETE)
    • URL path
    • HTTP version
  • Headers
    • Metadata (auth, content type, cookies, etc.)
  • Body (optional)
    • Data sent to server (e.g., JSON payload)

Example:

GET /api/users HTTP/1.1
Host: example.com
Authorization: Bearer <token>

HTTP Response

A response is sent from the server back to the client.

Structure:

  • Status Line
    • HTTP version
    • Status code
  • Headers
    • Metadata (Content-Type, caching, etc.)
  • Body
    • Actual response data (HTML, JSON, etc.)

Example:

HTTP/1.1 200 OK
Content-Type: application/json
{
  "name": "Alice"
}

HTTP Methods

Defines the type of operation the client wants to perform.

MethodDescriptionTypical BehaviorSide EffectsIdempotent
GETRetrieve data from the server without modifying itFetch a resource (e.g., webpage, API data)NoYes
POSTSend data to the server to create a new resource or trigger processingSubmit form data, create recordsYesNo
PUTReplace an existing resource or create it if it does not existFull update of a resourceYesYes
DELETERemove a resource from the serverDelete a file, database entry, or objectYesYes

Side effects: the operation changes something on the server or system state. Idempotent: doing the same operation multiple times has the same final effect as doing it once.

REST API

REST API is an architectural style for designing the application programming interface (API), commonly used over HTTP, to follow standard HTTP methods.

Key principles

  • Resource-based
    • Everything is a resource (users, orders, files)
    • Identified by URLs (e.g., /users/1)
  • Stateless
    • Each request contains all necessary information
    • Server does not store client session state
  • Uses HTTP methods
    • GET: read resource
    • POST: create resource
    • PUT: update resource
    • DELETE: remove resource

Public REST API

Some web servers or managed backend services with exposed public REST APIs, allowing users or applications to directly access and manipulate resources over HTTP. This is common in cloud services, backend platforms, and database.

HTTP Headers

Contain metadata about the request or response, providing additional context on how the message should be interpreted, processed, and handled.

Common header categories:

  • Authentication (Authorization)

    • Carries credentials used to authenticate the client
    • Common formats include:
      • Bearer <JWT token>
      • API keys
    • Used to verify identity and permissions before processing the request
  • Data format (Content-Type)

    • Specifies the format of the request or response body
    • Examples:
      • application/json
      • text/html
      • multipart/form-data
    • Ensures both client and server correctly parse the payload
  • Cookies (Cookie, Set-Cookie)

    • Used to maintain session state between requests
    • Client sends stored cookies using Cookie header
    • Server can set or update cookies using Set-Cookie
    • Commonly used for:
      • session management
      • user tracking
      • login persistence
  • Caching rules (Cache-Control, ETag)

    • Controls how responses are cached by browsers or intermediate proxies
    • Examples:
      • Cache-Control: no-cache
      • Cache-Control: max-age=3600
    • ETag helps determine whether cached content is still valid
    • Improves performance and reduces unnecessary network requests

Body

Contains actual data payload:

  • JSON
  • HTML
  • Form data (for POST)
  • File uploads

HTTP Status Codes

Indicate result of a request. The commonly used status codes are:

CodeMeaningDescription
200OKRequest succeeded
201CreatedResource created successfully
400Bad RequestInvalid request format
401UnauthorizedAuthentication required
403ForbiddenNo permission
404Not FoundResource does not exist
500Internal Server ErrorServer-side failure
502Bad GatewayInvalid response from upstream server

curl (Command-line HTTP Client)

curl is a command-line tool used to send HTTP requests and inspect HTTP responses directly from the terminal. It is commonly used for debugging, testing APIs, and monitoring network communication.

Basic usage

Send a GET request

curl https://example.com

Send a POST request

curl -X POST https://example.com/api/users \
     -H "Content-Type: application/json" \
     -d '{"name":"Alice"}'

Alternatively, one can use Postman for graphical interface.

Related articles

Network Interfaces and IP Address Fundamentals

A Network Interface is the connection point between a computer and a network. It is the operating system's abstraction of a network adapter, allowing applications to send and receive network traffi…

Training

Transport Layer Security (TLS)

TLS is a cryptographic protocol used to secure communication over a network. It is most commonly used in HTTPS, where it encrypts data between a client (browser) and a server. TLS ensures that data…

Training

Secure Shell Protocol (SSH)

SSH is a cryptographic network protocol used to securely access and manage remote computers over an unsecured network. It is commonly used for remote server administration, file transfer, and secur…

Training