Web / API Series

🎧 [Listen] The Web/API Series, Fully Recapped

This article is an audio-learning recap for anyone who’s already read all fifteen articles in the Web/API series. Use your browser’s or phone’s text-to-speech feature and let it play in the background during a commute or while doing chores. There are no diagrams, tables, or code here — just spoken-style prose, stitching the whole series back together into a single, continuous thread.

The series started with the fundamentals of what a RESTful API actually is. The starting point was that protocol and API are concepts at entirely separate layers — individual services publish their own distinct API, their own window, on top of HTTP, a shared, common set of manners. Every HTTP method carries its own meaning: GET and PUT are idempotent, designed so the result stays the same no matter how many times you run them, while POST is non-idempotent, potentially creating a new resource every time it runs. We also covered that authentication in a stateless world requires including a token with every single request, and how pagination returns a huge set of resources broken into pieces.

Next came what’s actually happening behind a payment API. Using Stripe as the example, we covered why payment never wraps up with a single, simple API call — it has a multi-stage lifecycle called PaymentIntent — and why a mechanism called a webhook becomes necessary to correctly detect when a payment actually completes. Never letting sensitive information, like a card number, touch the merchant’s own server at all was another important theme covered here.

Then came putting everything from the lecture into practice, hands-on, actually building an API server yourself. You confirmed POST’s non-idempotent behavior — sending it twice creates two separate resources with different IDs. And you confirmed PUT’s idempotent behavior — sending the same content to the same ID twice always converges the server’s state to the exact same single result. You got to feel firsthand that idempotency isn’t something the HTTP spec automatically guarantees — it’s a design agreement realized through the server’s own implementation.

Next came CORS. A “CORS error” that succeeds with curl or Postman but only fails from browser JavaScript happens not because the server is rejecting the request — it’s because the browser refuses to let JavaScript read the response. The Same-Origin Policy exists not to protect the server, but to protect the user themselves from an attack abusing their own browser session. And don’t forget: Content-Type: application/json isn’t included in the simple-request conditions, so most modern API calls sending JSON trigger a preliminary check called a preflight.

Next came ETags and conditional requests. Idempotency only guarantees safety for resending the same request — it never prevents the lost update problem, where two users update the same resource at the same time and one’s change silently gets overwritten by the other’s. An ETag is a unique identifier the server issues for a resource’s current state, used for two distinct purposes: If-None-Match for caching efficiency, and If-Match for detecting concurrent-update conflicts. If the ETag presented via If-Match doesn’t match the current state, the server returns 412 Precondition Failed — that was the real identity of HTTP’s standard optimistic lock.

From here, the series moved into more advanced territory. First, OAuth 2.0. The mechanism running behind a “Log in with Google” button turned out to be, not authentication, but authorization. We covered the authorization code flow’s two-stage design, built specifically to keep the powerful access token from ever traveling directly down the low-security browser redirect path. And we covered that achieving user authentication itself requires a separate spec, OpenID Connect, layered on top of OAuth 2.0.

Next came PKCE. A client secret was a secret known only to an app’s own server side, but a mobile app or SPA has no server side at all to begin with — no place to safely keep a secret. The mechanism that lets such a public client prevent authorization code interception without any client secret was PKCE, using a code_verifier/code_challenge pair. Even if an attacker intercepts the authorization code itself, an exchange request gets rejected by the authorization server without the code_verifier that exists only inside the legitimate app’s own memory. And don’t forget, under OAuth 2.1, PKCE is mandatory for every client, not just public ones.

Next came the difference between GraphQL and RESTful APIs. REST carries two contrasting problems: over-fetching, receiving more data than needed, and under-fetching, needing multiple calls just to render one screen. GraphQL eliminates both by letting the client side specify the exact shape of data it wants, as a query. The right way to understand this was never “which one is better” — it was a design-philosophy difference in who should decide the response’s shape, the server side or the client side.

Next came GraphQL’s N+1 problem and DataLoader. The flexibility of a resolver operating independently per field — the exact mechanism that solved over-fetching/under-fetching — is also exactly what causes a separate performance problem, the N+1 problem, firing one additional query per item in a list. DataLoader solves this by combining batching, converting individual resolver requests into one combined lookup, with deduplicating caching. And don’t forget: a DataLoader instance needs to be freshly rebuilt for every single request, to avoid an information leak.

Next came gRPC versus REST. gRPC is an option that achieves faster communication than REST/JSON through Protocol Buffers binary serialization and HTTP/2 multiplexing. But browser JavaScript can’t read the HTTP/2 trailers gRPC uses to convey a call’s final status, so a browser can’t call a gRPC server directly. A translating proxy called gRPC-Web has to sit in between, and even then, client-side streaming and bidirectional streaming aren’t supported. Never judge solely by the evaluation “gRPC is fast” — checking whether the caller is a browser or some other service mattered here too.

The final article put building a webhook receiver into practice, hands-on, with your own hands. Using an HMAC signature, the receiver recomputed the signature itself, with the same shared secret, and compared it against the signature that was sent, to verify the request genuinely came from its legitimate sender. Tampering with the payload’s content made that verification fail, correctly rejected with a 401 error. And you confirmed a deduplication mechanism too — sending a request with the same event ID twice skipped the actual processing on the second attempt. Signature verification and deduplication, serving entirely separate purposes as two separate defenses, took concrete shape here as actual implementation.

From here, more advanced hands-on labs followed, at graduation level. First, rate-limiting algorithms. You implemented the simplest approach, the fixed window, yourself, and confirmed with your own eyes a defect called the “boundary burst” — crossing a window boundary lets through roughly double the intended limit. Then you implemented the token bucket approach, and confirmed that under the exact same conditions, it only ever lets you consume however many tokens actually got refilled, enforcing a much smoother limit.

The final article was an educational, security-focused hands-on reproducing JWT’s “alg: none” vulnerability. When the server unconditionally trusts the alg value in a token’s own header and skips signature verification entirely once none is specified, you confirmed a freely crafted token, carrying no signature at all, still gets accepted with a forged admin role. And in the defended version, where the server fixes its allowed algorithms ahead of time, you confirmed the same forged token gets reliably rejected before ever reaching the signature-verification step. You got to confirm, with your own hands, the principle that an untrusted input’s content must never decide how that same input gets verified in the first place.

Next came another attack carrying the same principle — the algorithm confusion attack (RS256 to HS256). RS256 is an asymmetric scheme, signing with a private key and verifying with a public key, but if the server’s verification logic ends up reusing the exact key it had prepared for RS256 for HS256 verification too, an attacker can use the publicly available RS256 public key as the HMAC secret for HS256, and sign a forged token with it. The one reliable defense was explicitly pinning the allowed algorithm at verification time, never relying on the token’s own header. And don’t forget the perspective that “this information is public, so it’s safe” is only correct as long as that information is used for its intended purpose.

And the final article wasn’t like the others — it never taught a single new technique. Instead, under the setup of a fictional SaaS startup, KoiKoi Tasks, launching a public API platform for third-party developers, you designed, yourself, a single integrated API platform combining everything you’d learned separately up to that point: RESTful API idempotency design, authorization via OAuth 2.0, a structurally safe JWT verification implementation, rate limiting, and webhook signature verification and deduplication. Following a fixed procedure and designing from requirements are genuinely different skills, and finishing every individual hands-on doesn’t make you immediately effective in real work without experience combining them into one coherent platform.

Looking back across all fifteen articles, one consistent pattern emerges. The meaning behind idempotency itself, the algorithm confusion attack abusing an RS256 public key as an HMAC secret, a payment API’s multi-stage lifecycle, the division of roles between browser and server in CORS, ETag-based optimistic locking as the answer to what idempotency can never prevent, OAuth 2.0’s distinction between authentication and authorization, PKCE for a public client that can’t hold a client secret, REST versus GraphQL’s difference over who decides the response’s shape, that same flexibility’s surprising side effect of causing the N+1 problem, gRPC’s speed turning into a structural constraint the instant a browser is involved, the distinction between signature verification and deduplication in a webhook, the boundary condition a rate-limiting algorithm carries, the lesson that JWT verification must never let the input decide its own method, and the whole API platform integrated in the capstone — every one of them shared the same shape: behind one seemingly simple operation or term, several independent concepts or design decisions are actually combined together. Looking at an API’s behavior in front of you, and digging one layer deeper to ask what the real design intent underneath actually is. That’s the perspective a top-1% engineer carries away from this series. And that’s the recap of the Web/API series, complete.

Comments

Feel free to leave thoughts, questions, or corrections below (sign in with a GitHub account to comment or react).