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
api.example.com β localhost:8000, www.example.com β localhost:3000, assets β localhost:9000.198.51.100.24:53214 β 203.0.113.10:443.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.
AcceptContent-TypeCache-ControlETagvalidatorsAuthorizationWWW-AuthenticateCookieSet-CookieAccept-EncodingContent-EncodingTraceparentX-Request-IDJSONHTMLmultipartbinaryCommunication 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
Primitives, type coercion, let/const, functions & arrow functions
string
number
boolean
() =>
Objects & Context
Object literals, prototypes, this binding, classes & constructor patterns
this
bind
class
new
Arrays & Iteration
Functional array methods, higher-order functions, transformations & reductions
map
filter
reduce
sort
Errors & Async
Exception handling, promises, async/await, error propagation patterns
try/catch
Promise
async
await
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.