GET /api/users HTTP/1.1Introduction & Learning Goals
🎯 What You'll Learn
- Client-server architecture
- Request/response cycle
- Status codes & headers
- Functions, objects & arrays
- Async: Promises & async/await
- Modern ES6+ syntax
- DOM manipulation
- Events & event handling
- Fetch API & AJAX
- Server-side JavaScript
- File system & modules
- Building APIs
📚 Course Flow
- Understand how the web works: clients, servers, and HTTP.
- Refresh core JavaScript concepts and modern patterns.
- Apply JavaScript in the browser (DOM) and on the server (Node.js).
Web Foundations: HTTP
👥 Understanding the Actors
Every HTTP request involves a client and a server
🔄 Roles per request
A client starts a request; a server answers. In chains (your server → external API) the roles switch per hop.
Why ports
One IP, many apps. The OS delivers packets to the process bound to the destination port.
DNS → IP
Resolve example.com to an IP (cached by TTL). CDNs often answer with a nearby edge.
Connect, then HTTP
TCP 3‑way → TLS (for HTTPS) → send request line + headers → receive response.
Advanced: routing & sockets
- Reverse proxy routing: 443 (Nginx) can route
api.example.com→localhost:8000,www.example.com→localhost:3000, assets →localhost:9000. - Ephemeral client ports: Each connection is a 4‑tuple (clientIP:clientPort ⇄ serverIP:serverPort), e.g.
198.51.100.24:53214 ⇄ 203.0.113.10:443. - Anycast/CDN: One advertised IP maps to multiple edges; DNS and BGP steer you to a close POP.
Anatomy of HTTP Messages
A message = start line + headers + optional body. Each part has distinct semantics. Dive deeper for framing, wire format, and caching implications.
Status Codes: Semantics & Strategy
Status codes drive caching, retries, SEO, monitoring and auth flows before any body is read. Use precise codes consistently; guesswork costs performance.
Headers & Content Types (Quick View)
Headers = metadata; start line + headers often decide caching, routing, auth before body is read. Content type tells parsers how to treat the body.
- Negotiation:
Accept,Content-Type - Caching:
Cache-Control,ETag, validators - Auth:
Authorization,WWW-Authenticate - Session:
Cookie,Set-Cookie - Compression:
Accept-Encoding/Content-Encoding - Trace:
Traceparent,X-Request-ID - Representation: JSON, HTML, multipart, binary
Communication Examples
GET Request
A simple GET request to fetch a list of users. The client specifies it accepts JSON responses.
GET /api/users HTTP/1.1
Host: example.com
Accept: application/json
POST Request
A POST request to create a new user. The body contains JSON data with the user's information.
POST /api/users HTTP/1.1
Host: example.com
Content-Type: application/json
{"name":"Mehdi","role":"student"}
Server Response
A successful response with caching headers, compression, and an ETag for future revalidation.
HTTP/1.1 200 OK
Date: Thu, 06 Nov 2025 10:11:12 GMT
Server: example-app
Content-Type: application/json; charset=utf-8
Cache-Control: max-age=60, public
ETag: "users:v1:af31b2"
X-Request-ID: 8b7c2f55-91d7-4e6a-8209-9f8a1f4c1c21
Content-Encoding: br
[{"id":1,"name":"Mehdi"},{"id":2,"name":"Ada"}]
Reading the response without the body: Status + headers already tell success, cacheability, compression, and revalidation strategy (ETag). Monitoring often ignores the body.
JavaScript Overview
⚙️ How JavaScript Works
Engines & the Language
JS engines (like V8, SpiderMonkey) implement the ECMAScript standard. JS is single‑threaded with an event loop; asynchronous work uses callbacks, promises, and async/await.
Core Concepts at a Glance
- Types, variables, functions, and arrow functions
- Objects and
thissemantics - Arrays and array methods (
map,filter,reduce,sort) - Errors,
try/catch, and promises
Deep dive in the Language Refresher.
Node.js Runtime
🚀 Node.js Architecture
Idea behind Node.js
Node.js runs JavaScript on the server using the V8 engine plus system bindings for files, network, and more. It’s great for I/O‑heavy apps.
Learn more
See the dedicated Node.js page for examples and patterns.