Skip to content
Chapter 11Lesson 4

Quiz - The HTTP contract every endpoint signs

Quiz progress

0 / 0

A POST /invoices route handler runs safeParse on the request body. The JSON parses fine, but the schema rejects the value because dueDate is in the past. What status code should the response carry?

400 Bad Request — the request was rejected, and 400 is the generic client-fault code.

422 Unprocessable Content — the body parsed cleanly but a business rule rejected the parsed value.

409 Conflict — the date conflicts with the server’s notion of “today.”

A wallet endpoint receives PATCH /wallets/42 with the body { "delta": 5 } and the server adds 5 to the current balance on every call. The client retries the same request after a network blip. Is the endpoint idempotent?

Yes — PATCH is idempotent per the HTTP spec.

No — the diff is relative, so each retry shifts the final state by another 5.

Only if the server sets Content-Type: application/merge-patch+json on the response.

A page at /invoices is server-rendered, varies by the signed-in user’s organization, and is reached via a sidebar link. Which Cache-Control value is the senior 2026 default for the response?

public, max-age=300

private, max-age=300

private, no-store

no-cache

Pick the statements that describe correct 2026 senior defaults for status codes. Select all that apply.

A signed-in user requests an invoice that belongs to a different organization — the response is 404 Not Found, not 403 Forbidden.

An unhandled TypeError bubbles to the framework boundary — the response is 503 Service Unavailable.

A form submission succeeds and the server redirects to a detail page the user should reach with GET — the response is 303 See Other with a Location header.

A successful DELETE that returns no body — the response is 200 OK with an empty JSON object.

A SaaS rate limiter behind Vercel reads the client IP from request.headers.get('x-forwarded-for') and uses the leftmost entry to key its bucket. What’s wrong with this?

Nothing — X-Forwarded-For is appended in order by each proxy, so the leftmost entry is the original client.

The leftmost entry is whatever the original client sent and can be forged; only the rightmost hop (or the value the trusted edge appended, e.g. x-vercel-forwarded-for) is trustworthy.

X-Forwarded-For was retired by RFC 7239; the limiter should read Forwarded instead, which is unforgeable.

A payments client retries POST /payments/charge after a network blip. The team wants the retry to be safe. Which implementation actually closes the duplicate-charge hole?

The client generates a fresh Idempotency-Key for each network attempt and sends it on every retry.

The client generates one Idempotency-Key per logical operation, reuses it on every retry, and the server stores (key, response) before sending the response back.

The server returns 200 OK on the original request and 409 Conflict on any duplicate body it sees within a minute.

In a Next.js 16 app, which file is the right place to set the per-request CSP nonce header?

next.config.ts headers() — it’s a security header and lives with HSTS and Referrer-Policy.

proxy.ts — the nonce has to be fresh per request, so it needs request-time data.

The route handler’s Response — every route should mint its own nonce alongside the body.

Quiz complete

Score by topic