1. Foundations & Architecture

Client-Server & HTTP Protocol

Before diving into web frameworks like Spring Boot, we must understand the foundational networking layer - how code running on one machine communicates with code running on another machine across a network.

1. Client-Server Architecture

In modern web development, applications operate on a client-server model:

  • Client: The requesting entity (e.g., web browser, mobile application, Postman, CLI tool).
  • Server: The processing entity (e.g., Java application running on a remote host or cloud instance).
HTTP Request (Method, URL, Headers, Body) HTTP Response (Status Code, Headers, Body) Server processes request,executes logic, reads database Client (Browser / App) Web Server (Application Host)

Analogy: A Restaurant Ordering System

Think of backend application architecture as a restaurant:

Technical ComponentReal-World EquivalentRole
ClientCustomerInitiates the request by asking for a service or resource.
HTTP RequestCustomer's Order FormFormatted document stating what item is requested and giving options.
Server HostRestaurant BuildingPhysical location providing infrastructure.
IP AddressStreet AddressUnique location locator on the global network.
PortEntrance Door / Service CounterSpecific listening endpoint for a given service.
HTTP ResponseServed Meal + ReceiptThe result returned to the customer, complete with metadata and status.

2. Networking Primitives: IP, Ports, Sockets & URLs

IP Addresses (127.0.0.1 vs External)

An IP (Internet Protocol) Address uniquely identifies a physical or virtual machine on a network.

  • Public/Private IP: e.g., 192.168.1.50 or 172.217.14.206.
  • Loopback IP (127.0.0.1): A special IP address reserved for a host to refer to itself. localhost is a domain name that resolves to 127.0.0.1.

Port Numbers

While an IP address gets network packets to a specific computer, a computer runs hundreds of processes simultaneously. A Port Number (0–65535) routes traffic to a specific application process.

IP Address (Building)  -->  Port Number (Apartment Number / Door)
192.168.1.100                :8080 (Spring Boot Application)
                             :5432 (PostgreSQL Database)
                             :3306 (MySQL Database)

Common Standard Ports

Protocol / ApplicationDefault Port
HTTP80 (Browsers omit this automatically)
HTTPS443 (Browsers omit this automatically)
SSH22
Spring Boot Embedded Server8080 (Default dev port)
PostgreSQL5432

URL Anatomy

A URL (Uniform Resource Locator) decomposes into specific structural components:

  http:// localhost : 8080 /api/v1/users ? status=active # profile
  │───┘   │───────┘   └──┘ └───────────┘ └──────────────┘ └──────┘
Scheme    Host        Port     Path       Query Params    Fragment
  1. Scheme/Protocol: http:// or https:// (Defines communication protocol).
  2. Host: localhost or api.example.com (Identifies target server).
  3. Port: :8080 (Target application socket door).
  4. Path: /api/v1/users (Identifies target resource endpoint).
  5. Query Parameters: ?status=active (Key-value filter parameters).
  6. Fragment/Hash: #profile (Client-side UI anchor, never sent to server).

3. HTTP: The Language of the Web

HTTP (HyperText Transfer Protocol) is an application-layer, stateless request-response protocol running on top of TCP/IP.

Analogy: A Courier Package

An HTTP transmission behaves like sending a parcel:

Courier Package
├── Label (Headers)
│   ├── Destination / Path
│   ├── Content-Type (JSON, HTML)
│   └── Sender Credentials (Auth Token)
└── Contents (Body)
    └── Payload Data

HTTP Request Structure

An HTTP request consists of four primary parts:

  1. HTTP Method: Verb defining desired action.
  2. Path / URL: Target resource identifier.
  3. Headers: Key-value metadata.
  4. Body: Payload (optional in GET/DELETE, mandatory in POST/PUT/PATCH).
POST /api/v1/orders HTTP/1.1
Host: api.store.com
Content-Type: application/json
Authorization: Bearer eyJhbGciOi...

{
  "productId": 4021,
  "quantity": 2
}

HTTP Methods & Semantic Rules

MethodIntended MeaningIdempotent?Safe?Request Body?
GETRead data from serverYesYesNo
POSTCreate a new resourceNoNoYes
PUTReplace target resource completelyYesNoYes
PATCHUpdate specific fields partiallyNoNoYes
DELETERemove target resourceYesNoOptional

Idempotency Rule: An operation is idempotent if making the same request multiple times produces the exact same side-effect on the server as making it once. PUT is idempotent (replacing a file 10 times yields the same state); POST is non-idempotent (creating 10 orders yields 10 database rows).

PUT vs PATCH Engineering Distinction

  • PUT replaces the entire object state. Omitted fields are reset to default/null.
  • PATCH updates only specified attributes, leaving existing attributes untouched.

4. HTTP Headers & Status Codes

Key Headers

Header CategoryKey HeaderUsage
Content NegotiationContent-TypeTells receiver format of current body (e.g., application/json).
Content NegotiationAcceptTells server format client expects in response (e.g., application/json).
Security / AuthAuthorizationPasses identity tokens (e.g., Bearer <token>, Basic <base64>).
Host RoutingHostVirtual host name of target server.
CachingCache-ControlDirectives for browser/CDN caching policies.

HTTP Status Code Taxonomy

Status codes are 3-digit numerical responses indicating result categories:

Status Code Ranges:
├── 1xx (Informational) -> Protocol switching, processing
├── 2xx (Success)       -> 200 OK, 201 Created, 204 No Content
├── 3xx (Redirection)   -> 301 Moved Permanently, 304 Not Modified
├── 4xx (Client Error)  -> 400 Bad Request, 401 Unauthorized, 403 Forbidden, 404 Not Found
└── 5xx (Server Error)  -> 500 Internal Server Error, 502 Bad Gateway, 503 Service Unavailable
Status CodeNameDescription & Usage
200 OKRequest SucceededStandard response for GET, PUT, PATCH, DELETE operations.
201 CreatedResource CreatedStandard response for successful POST creation.
204 No ContentExecuted, No BodyRequest succeeded, but response body is empty (common for DELETE).
400 Bad RequestClient Payload ErrorInvalid JSON, missing required body field, validation failure.
401 UnauthorizedUnauthenticatedMissing or invalid authentication token.
403 ForbiddenAccess DeniedClient authenticated, but lacks permissions for resource.
404 Not FoundEndpoint/Resource MissingInvalid URL path, or database ID does not exist.
500 Server ErrorApplication CrashUnhandled Exception thrown on server thread.

❓ Knowledge Check

Knowledge Check

What is the key semantic difference between HTTP PUT and HTTP PATCH?

Knowledge Check

Which component of a URL tells the operating system which specific application process should receive incoming network traffic?

On this page