Web, HTTP, HTTPS, JSON & API Foundations
Every backend and frontend lesson depends on one journey: a user names a host, DNS resolves it, a connection is established and protected by TLS, HTTP carries a typed contract, intermediaries route or cache it, and browser security rules…
- Explain Internet request path by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain HTTP contract by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain API design basics by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Trace the chapter's complete execution path and identify where memory, I/O, concurrency, persistence, or rendering cost accumulates.
- Build the worked example, make one failure visible, and defend the design in a review.
How to use this chapter
For Web, HTTP, HTTPS, JSON & API Foundations, read the explanations first and predict every example before running it. Keep a learning repository containing code, tests, command output, and the short written submission. The roadmap checklist at the end audits coverage; the chapter itself follows the protocol learning arc appropriate to this subject.
The problem this chapter solves
Every backend and frontend lesson depends on one journey: a user names a host, DNS resolves it, a connection is established and protected by TLS, HTTP carries a typed contract, intermediaries route or cache it, and browser security rules decide what client code may do.
Full-stack code communicates through layered network and HTTP contracts. Separating DNS, transport, TLS, HTTP, caching, identity, and browser policy makes failures diagnosable and APIs evolvable.
Learning outcomes
- Explain Internet request path by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain HTTP contract by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Explain API design basics by naming its input, guarantee, internal lifecycle, important failure, and proof.
- Trace the chapter's complete execution path and identify where memory, I/O, concurrency, persistence, or rendering cost accumulates.
- Build the worked example, make one failure visible, and defend the design in a review.
Chapter progression
The order below is intentional: later sections depend on guarantees established earlier.
Runtime or system overview
A client resolves a host, selects an address, establishes TCP or QUIC state, negotiates TLS, serializes an HTTP request, and receives a status, headers, and optional representation through intermediaries. Browsers then apply cookie, origin, CORS, CSP, caching, and response-processing rules. In Web, HTTP, HTTPS, JSON & API Foundations, use that execution model to decide where the chapter's validation, state ownership, cleanup, and evidence belong.
Execution trace
- The client parses the URL and asks DNS for the host address.
- It establishes TCP state and validates the server certificate during TLS.
- The HTTP request sends method, target, headers, and optional body through trusted intermediaries.
- The application returns a status, metadata, and representation; caches apply explicit rules.
- The browser or client enforces origin, cookie, redirect, and response-processing policy.
Memory and performance lens
Clients and servers retain connection state, TLS sessions, header tables, request/response buffers, cookies, caches, and in-flight body data. Streaming and explicit size limits prevent one request or unbounded response from monopolizing memory. For Web, HTTP, HTTPS, JSON & API Foundations, connect those costs to the concrete operations in the topic sections rather than assuming the friendly surface syntax is cheap.
When tuning Web, HTTP, HTTPS, JSON & API Foundations, measure DNS/TCP/TLS timing, status and header behavior, bytes transferred, cache outcome, retry count, and end-to-end p95/p99 latency rather than optimizing from source-code appearance.
1. Internet request path
The Internet request path unit begins with DNS resolution and IP routing: DNS translates a host name into records such as IP addresses; IP routing forwards packets hop by hop toward the selected address. Use names instead of hard-coded addresses, configure sensible DNS caching, and diagnose name resolution separately from transport/application failures. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
The protocol contract: Internet request path
| Concept | Meaning | Engineering decision |
|---|---|---|
| DNS resolution and IP routing | DNS translates a host name into records such as IP addresses; IP routing forwards packets hop by hop toward the selected address. | Use names instead of hard-coded addresses, configure sensible DNS caching, and diagnose name resolution separately from transport/application failures. |
| TCP connection and TLS handshake | TCP provides an ordered byte stream between endpoints; TLS authenticates the server and encrypts and integrity-protects bytes carried over that connection. | Use HTTPS with verified certificates, timeouts, modern protocol versions, and connection reuse. |
| HTTP request/response lifecycle | HTTP exchanges a method, target, headers, and optional body for a status, headers, and optional response body; intermediaries may route, terminate TLS, or cache along the path. | Propagate correlation and forwarding metadata through trusted proxies and define which responses may be cached. |
| proxies, load balancers and CDNs | HTTP exchanges a method, target, headers, and optional body for a status, headers, and optional response body; intermediaries may route, terminate TLS, or cache along the path. | Propagate correlation and forwarding metadata through trusted proxies and define which responses may be cached. |
Follow bytes, identity, and metadata: Internet request path
DNS resolution and IP routing. Resolvers consult local caches and recursive DNS services, which follow delegated authoritative records. Routers select next hops from routing tables; the path can change between connections.
TCP connection and TLS handshake. TCP establishes sequence state and retransmits loss. During TLS, peers negotiate algorithms, validate the certificate chain and host name, derive session keys, and only then exchange protected application data.
HTTP request/response lifecycle. A client serializes a request over an HTTP connection. Reverse proxies and load balancers select an upstream; the application returns a response; caches apply freshness and validation rules.
proxies, load balancers and CDNs. A client serializes a request over an HTTP connection. Reverse proxies and load balancers select an upstream; the application returns a response; caches apply freshness and validation rules.
Read these as one system: DNS resolution and IP routing establishes the starting contract, TCP connection and TLS handshake changes how that contract is executed or represented, and proxies, load balancers and CDNs exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Inspect a real exchange: Internet request path
1dig +short api.example.com2traceroute api.example.com3# On Windows use nslookup and tracert.This Internet request path slice makes DNS resolution and IP routing observable. Read it from the boundary inward: identify the input, the validation point, the state or operation, and the value that proves the result. Before extending it toward proxies, load balancers and CDNs, predict its behavior for empty, invalid, repeated, and large input.
Network and browser boundary failures: Internet request path
| Risk | Why it matters |
|---|---|
| DNS resolution and IP routing | A successful DNS answer does not prove the service is reachable, authorized, healthy, or serving the expected certificate. |
| TCP connection and TLS handshake | Disabling certificate verification defeats server authentication and permits interception even though traffic still appears encrypted. |
| HTTP request/response lifecycle | Trusting client-supplied forwarding headers or caching personalized responses under a shared key can expose identities and data. |
| proxies, load balancers and CDNs | Trusting client-supplied forwarding headers or caching personalized responses under a shared key can expose identities and data. |
Protocol investigation: Internet request path
- Foundation: implement or demonstrate DNS resolution and IP routing with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine DNS resolution and IP routing with TCP connection and TLS handshake. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for proxies, load balancers and CDNs. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
2. HTTP contract
The HTTP contract unit begins with methods and safe/idempotent semantics: HTTP method semantics describe the requested action, while status and representation metadata describe the result and payload format. Return specific statuses, declare Content-Type, validate Accept where representation varies, and use idempotency keys for retryable create workflows. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
The protocol contract: HTTP contract
| Concept | Meaning | Engineering decision |
|---|---|---|
| methods and safe/idempotent semantics | HTTP method semantics describe the requested action, while status and representation metadata describe the result and payload format. | Return specific statuses, declare Content-Type, validate Accept where representation varies, and use idempotency keys for retryable create workflows. |
| status code families | HTTP method semantics describe the requested action, while status and representation metadata describe the result and payload format. | Return specific statuses, declare Content-Type, validate Accept where representation varies, and use idempotency keys for retryable create workflows. |
| headers, media types and content negotiation | HTTP method semantics describe the requested action, while status and representation metadata describe the result and payload format. | Return specific statuses, declare Content-Type, validate Accept where representation varies, and use idempotency keys for retryable create workflows. |
| cookies, sessions and bearer tokens | Cookies are browser-managed values scoped by domain/path/security attributes; sessions map a cookie identifier to server state; bearer tokens grant whoever possesses them the encoded or referenced authority. | Use Secure, HttpOnly, and appropriate SameSite cookies, CSRF tokens for cookie-authenticated unsafe actions, narrow CORS, and server-side authorization. |
Follow bytes, identity, and metadata: HTTP contract
methods and safe/idempotent semantics. Servers route by method and target, parse headers and media types, and choose a representation. Safe methods should not request state change; idempotent methods may be repeated with the same intended effect.
status code families. Servers route by method and target, parse headers and media types, and choose a representation. Safe methods should not request state change; idempotent methods may be repeated with the same intended effect.
headers, media types and content negotiation. Servers route by method and target, parse headers and media types, and choose a representation. Safe methods should not request state change; idempotent methods may be repeated with the same intended effect.
cookies, sessions and bearer tokens. Browsers attach matching cookies automatically, which creates CSRF risk for unsafe actions. CORS controls which origins may read browser responses; it is not server authorization.
Read these as one system: methods and safe/idempotent semantics establishes the starting contract, status code families changes how that contract is executed or represented, and cookies, sessions and bearer tokens exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Inspect a real exchange: HTTP contract
1PUT /profiles/42 HTTP/1.12Host: api.example.test3Content-Type: application/json4Idempotency-Key: profile-42-v75
6{"display_name":"Dev"}This HTTP contract slice makes methods and safe/idempotent semantics observable. Read it from the boundary inward: identify the input, the validation point, the state or operation, and the value that proves the result. Before extending it toward cookies, sessions and bearer tokens, predict its behavior for empty, invalid, repeated, and large input.
Network and browser boundary failures: HTTP contract
| Risk | Why it matters |
|---|---|
| methods and safe/idempotent semantics | Treating POST as automatically non-repeatable or returning 200 for every error makes clients unsafe and contracts ambiguous. |
| status code families | Treating POST as automatically non-repeatable or returning 200 for every error makes clients unsafe and contracts ambiguous. |
| headers, media types and content negotiation | Treating POST as automatically non-repeatable or returning 200 for every error makes clients unsafe and contracts ambiguous. |
| cookies, sessions and bearer tokens | Storing long-lived tokens in script-readable storage or using wildcard credentialed CORS increases account and data exposure. |
Protocol investigation: HTTP contract
- Foundation: implement or demonstrate methods and safe/idempotent semantics with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine methods and safe/idempotent semantics with status code families. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for cookies, sessions and bearer tokens. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
3. API design basics
The API design basics unit begins with resources and URLs: An API represents domain resources through stable identifiers, typed representations, bounded collections, and machine-readable errors. Use nouns for resource paths, deterministic ordering, explicit schemas, stable error codes, and cursors for frequently changing large collections. The rest of this section connects that guarantee to this unit's related roadmap concepts instead of treating each term as an isolated flashcard.
The protocol contract: API design basics
| Concept | Meaning | Engineering decision |
|---|---|---|
| resources and URLs | An API represents domain resources through stable identifiers, typed representations, bounded collections, and machine-readable errors. | Use nouns for resource paths, deterministic ordering, explicit schemas, stable error codes, and cursors for frequently changing large collections. |
| JSON types and schema validation | An API represents domain resources through stable identifiers, typed representations, bounded collections, and machine-readable errors. | Use nouns for resource paths, deterministic ordering, explicit schemas, stable error codes, and cursors for frequently changing large collections. |
| pagination, filtering and errors | An API represents domain resources through stable identifiers, typed representations, bounded collections, and machine-readable errors. | Use nouns for resource paths, deterministic ordering, explicit schemas, stable error codes, and cursors for frequently changing large collections. |
| CORS, CSRF and browser security boundaries | Cookies are browser-managed values scoped by domain/path/security attributes; sessions map a cookie identifier to server state; bearer tokens grant whoever possesses them the encoded or referenced authority. | Use Secure, HttpOnly, and appropriate SameSite cookies, CSRF tokens for cookie-authenticated unsafe actions, narrow CORS, and server-side authorization. |
Follow bytes, identity, and metadata: API design basics
resources and URLs. The server separates path identity, query selection, headers, and body data; validation produces typed values before domain logic. Pagination bounds database and network work.
JSON types and schema validation. The server separates path identity, query selection, headers, and body data; validation produces typed values before domain logic. Pagination bounds database and network work.
pagination, filtering and errors. The server separates path identity, query selection, headers, and body data; validation produces typed values before domain logic. Pagination bounds database and network work.
CORS, CSRF and browser security boundaries. Browsers attach matching cookies automatically, which creates CSRF risk for unsafe actions. CORS controls which origins may read browser responses; it is not server authorization.
Read these as one system: resources and URLs establishes the starting contract, JSON types and schema validation changes how that contract is executed or represented, and CORS, CSRF and browser security boundaries exposes a later boundary or failure condition. A local optimization is useful only when the combined behavior stays correct and observable.
Inspect a real exchange: API design basics
1GET /v1/projects/8/tasks?status=open&limit=20 HTTP/1.12Host: api.example.test3Accept: application/jsonThis API design basics slice makes resources and URLs observable. Read it from the boundary inward: identify the input, the validation point, the state or operation, and the value that proves the result. Before extending it toward CORS, CSRF and browser security boundaries, predict its behavior for empty, invalid, repeated, and large input.
Network and browser boundary failures: API design basics
| Risk | Why it matters |
|---|---|
| resources and URLs | Returning unbounded arrays, leaking stack traces, or coupling public JSON directly to database fields makes the API unsafe and hard to evolve. |
| JSON types and schema validation | Returning unbounded arrays, leaking stack traces, or coupling public JSON directly to database fields makes the API unsafe and hard to evolve. |
| pagination, filtering and errors | Returning unbounded arrays, leaking stack traces, or coupling public JSON directly to database fields makes the API unsafe and hard to evolve. |
| CORS, CSRF and browser security boundaries | Storing long-lived tokens in script-readable storage or using wildcard credentialed CORS increases account and data exposure. |
Protocol investigation: API design basics
- Foundation: implement or demonstrate resources and URLs with one valid input and one invalid input. Record the exact output or failure.
- Integration: combine resources and URLs with JSON types and schema validation. Explain which component owns validation and cleanup.
- Production: design a test or experiment that exposes the failure described for CORS, CSRF and browser security boundaries. State the metric, assertion, or query plan that proves the correction.
What a strong checkpoint answer contains
- A precise boundary and typed or validated input.
- One named guarantee, not only a library call.
- A negative case that fails for the intended reason.
- Cleanup, transaction, retry, or cancellation behavior where applicable.
- Evidence: assertion, command output, plan, trace, metric, or accessible UI state.
Complete worked example
This example integrates the chapter rather than demonstrating an isolated method.
1curl --silent --show-error --dump-header headers.txt \2 --output response.json \3 --connect-timeout 3 --max-time 10 \4 --header 'Accept: application/vnd.github+json' \5 --header 'User-Agent: full-stack-course-client' \6 https://api.github.com/repos/python/cpython7printf 'status and headers\n'8sed -n '1,12p' headers.txtExpected result
1The command records the response representation separately from status and headers, fails visibly on transport errors, and bounds connection and total time.Line-by-line reading
| Line | Code | Explanation |
|---|---|---|
| 1 | curl --silent --show-error --dump-header headers.txt \ | Implements the next bash statement in the example's data flow. |
| 2 | --output response.json \ | Implements the next bash statement in the example's data flow. |
| 3 | --connect-timeout 3 --max-time 10 \ | Implements the next bash statement in the example's data flow. |
| 4 | --header 'Accept: application/vnd.github+json' \ | Implements the next bash statement in the example's data flow. |
| 5 | --header 'User-Agent: full-stack-course-client' \ | Implements the next bash statement in the example's data flow. |
| 6 | https://api.github.com/repos/python/cpython | Implements the next bash statement in the example's data flow. |
| 7 | printf 'status and headers\n' | Emits the example's observable output. |
| 8 | sed -n '1,12p' headers.txt | Implements the next bash statement in the example's data flow. |
Step-by-step execution
- The client parses the URL and asks DNS for the host address.
- It establishes TCP state and validates the server certificate during TLS.
- The HTTP request sends method, target, headers, and optional body through trusted intermediaries.
- The application returns a status, metadata, and representation; caches apply explicit rules.
- The browser or client enforces origin, cookie, redirect, and response-processing policy.
Common mistakes and professional corrections
| Area | Common failure | Better engineering choice |
|---|---|---|
| Internet request path | A successful DNS answer does not prove the service is reachable, authorized, healthy, or serving the expected certificate. | Use names instead of hard-coded addresses, configure sensible DNS caching, and diagnose name resolution separately from transport/application failures. |
| HTTP contract | Treating POST as automatically non-repeatable or returning 200 for every error makes clients unsafe and contracts ambiguous. | Return specific statuses, declare Content-Type, validate Accept where representation varies, and use idempotency keys for retryable create workflows. |
| API design basics | Returning unbounded arrays, leaking stack traces, or coupling public JSON directly to database fields makes the API unsafe and hard to evolve. | Use nouns for resource paths, deterministic ordering, explicit schemas, stable error codes, and cursors for frequently changing large collections. |
Interview and review notes
- Define the central abstraction without naming a library function.
- Trace one request, call, query, message, render, or state transition from input to observable result.
- Compare two alternatives from this chapter by guarantee, cost, and failure behavior.
- Explain the most likely production bug and the test or metric that reveals it.
- State what remains authoritative after process loss, retry, reconnect, or deployment.
Practice set
Easy
- Define every bold term in the concept tables in one precise sentence.
- Reproduce the focused examples and annotate the value or state after each important line.
- Explain the chapter progression diagram aloud in two minutes.
Medium
- Replace one convenient default with an explicit policy for validation, timeout, ordering, pagination, cleanup, or error handling.
- Write a negative test for each topic group.
- Compare the measured behavior before and after one justified change.
Hard
- Combine all topic groups into one thin vertical slice.
- Inject a realistic failure at the most important external boundary and prove recovery.
- Write a one-page design note covering ownership, trade-offs, security, observability, and rollback.
Chapter submission
Submit:
- source code or reproducible commands;
- automated tests plus one deliberately failing-before-fix test;
- captured output, query plan, trace, screenshot, or metric;
- a 300–500 word explanation of the execution flow and one rejected alternative;
- a short README with setup, versions, limitations, and cleanup steps.
Self-review rubric
| Dimension | Beginning | Competent | Professional |
|---|---|---|---|
| Explanation | Names APIs | Explains behavior | Connects guarantees, internals, and trade-offs |
| Implementation | Happy path only | Validated and tested | Clear ownership, failure recovery, and cleanup |
| Evidence | Manual claim | Repeatable output | Tests plus meaningful measurement or inspection |
| Communication | Steps missing | Reproducible README | Decisions, limits, and alternatives are explicit |
Roadmap coverage checklist
- To do: Internet request path: DNS resolution and IP routing
- To do: Internet request path: TCP connection and TLS handshake
- To do: Internet request path: HTTP request/response lifecycle
- To do: Internet request path: proxies, load balancers and CDNs
- To do: HTTP contract: methods and safe/idempotent semantics
- To do: HTTP contract: status code families
- To do: HTTP contract: headers, media types and content negotiation
- To do: HTTP contract: cookies, sessions and bearer tokens
- To do: API design basics: resources and URLs
- To do: API design basics: JSON types and schema validation
- To do: API design basics: pagination, filtering and errors
- To do: API design basics: CORS, CSRF and browser security boundaries
Quick revision
- Internet request path: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- HTTP contract: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- API design basics: connect the surface API to its guarantee, lifecycle, failure boundary, and evidence.
- Re-read the worked-example execution trace instead of memorizing isolated syntax.
- If you cannot name the owner of state and cleanup, the design is not yet complete.
Mastery check
How well can you recall this?
Finished this lesson?