Episode 2 — React Frontend Architecture NextJS / 2.20 — Building APIs with NextJS
2.20.b — HTTP Methods (GET → DELETE)
In one sentence: You model REST-ish behavior by exporting one async function per HTTP verb — each parses the incoming
Request, performs work, and returns aResponsewith a deliberate status code and body.
Navigation: ← Route Handlers & Conventions · Next → Databases
1. Supported Named Exports
Typical exports (Node / standard Web semantics):
| Export | Meaning |
|---|---|
GET | Safe reads, cacheable in principle |
POST | Create resource or non-idempotent commands |
PUT | Replace entire resource (idempotent when addressed to stable URI) |
PATCH | Partial update |
DELETE | Remove resource |
HEAD, OPTIONS | Specialized — use when needed |
If a client calls PATCH but you only exported PUT and POST, they get 405 (unless you add PATCH).
2. Handler Signature (App Router)
import { NextRequest, NextResponse } from 'next/server';
type Ctx = { params: Promise<{ id: string }> }; // Next 15+: params may be async
export async function GET(request: NextRequest, context: Ctx) {
const { id } = await context.params;
const q = request.nextUrl.searchParams.get('q');
return NextResponse.json({ id, q });
}
Note on params: In Next.js 15, context.params is a Promise in many route contexts. Always await context.params in new code. Older tutorials show sync params — verify your version.
3. GET — Reads, Query Strings, Caching Hints
export async function GET(request: NextRequest) {
const limit = Number(request.nextUrl.searchParams.get('limit') ?? '20');
const safeLimit = Number.isFinite(limit) ? Math.min(Math.max(limit, 1), 100) : 20;
// const rows = await listUsers({ limit: safeLimit });
return NextResponse.json({ data: [], meta: { limit: safeLimit } });
}
GET should not mutate data that matters for correctness (analytics pixels aside). Violating this breaks caches, proxies, and user expectations.
Caching: GET Route Handlers can set Cache-Control and use Next’s fetch cache in downstream data loading — but for JSON APIs you often return no-store unless you have a deliberate CDN strategy.
4. POST — Create, JSON Body, 201 + Location
export async function POST(request: Request) {
let body: unknown;
try {
body = await request.json();
} catch {
return NextResponse.json({ error: { code: 'INVALID_JSON', message: 'Body must be JSON' } }, { status: 400 });
}
// validate with Zod, etc.
const created = { id: 'usr_01', email: (body as { email?: string }).email };
return NextResponse.json({ data: created }, { status: 201, headers: { Location: `/api/users/${created.id}` } });
}
Status codes (typical):
201 Created— resource created;Locationheader optional but nice.400— malformed JSON or failed validation.409— conflict (duplicate email).
5. PUT — Full Replace
Use when the client sends a complete representation of the resource.
export async function PUT(request: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const body = await request.json();
// replaceResource(id, body) — missing fields may reset to defaults or null per your API contract
return NextResponse.json({ data: { id, ...body } });
}
Interview nuance: Many teams treat PUT vs PATCH loosely; document your contract. Strict REST: PUT is idempotent full replacement.
6. PATCH — Partial Update
export async function PATCH(request: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
const partial = await request.json();
// mergePatch(id, partial)
return NextResponse.json({ data: { id, name: partial.name } });
}
Return 200 with the updated body, or 204 No Content if you prefer empty success bodies (then clients must re-fetch if they need the row).
7. DELETE — Remove
export async function DELETE(_request: Request, context: { params: Promise<{ id: string }> }) {
const { id } = await context.params;
// const existed = await deleteUser(id);
const existed = true;
if (!existed) {
return NextResponse.json({ error: { code: 'NOT_FOUND', message: 'User not found' } }, { status: 404 });
}
return new Response(null, { status: 204 });
}
Common status codes: 204 success no body, 404 if missing, 403 if not allowed to delete.
8. Method Not Allowed Helper Pattern
When several verbs share validation, extract helpers — but each export stays thin:
async function parseJson(request: Request): Promise<{ ok: true; value: unknown } | { ok: false; response: Response }> {
try {
return { ok: true, value: await request.json() };
} catch {
return {
ok: false,
response: NextResponse.json({ error: { code: 'INVALID_JSON' } }, { status: 400 }),
};
}
}
9. OPTIONS / CORS (Sketch)
Browsers send preflight OPTIONS for cross-origin JSON with custom headers. If you expose a public API from another origin:
export async function OPTIONS() {
return new NextResponse(null, {
status: 204,
headers: {
'Access-Control-Allow-Origin': 'https://trusted.example',
'Access-Control-Allow-Methods': 'GET,POST,PATCH,DELETE,OPTIONS',
'Access-Control-Allow-Headers': 'Content-Type, Authorization',
'Access-Control-Max-Age': '86400',
},
});
}
Repeat needed CORS headers on actual responses or use middleware — production setups often centralize this.
10. Verb Cheat Sheet (Memorize)
| Verb | Body typical? | Idempotent? | Safe? |
|---|---|---|---|
| GET | No | Yes | Yes |
| POST | Yes | No | No |
| PUT | Yes | Yes* | No |
| PATCH | Yes | No (usually) | No |
| DELETE | Sometimes | Yes | No |
*PUT idempotency: repeating the same full payload should leave the resource in the same state.
Next: 2.20.c — Connecting APIs to Databases
Part 2 — Deep Encyclopedia (HTTP methods)
How to use this section: Read sequentially or jump by drill number. Each block has a scenario, a prompt (what an interviewer might ask), a model answer, and often a code sketch.
E001 — API drill 1: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 1: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #1.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #1, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E002 — API drill 2: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 2: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #2.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #2, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E003 — API drill 3: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 3: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #3.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #3, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E004 — API drill 4: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 4: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #4.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #4, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E005 — API drill 5: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 5: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #5.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #5, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E006 — API drill 6: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 6: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #6.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #6, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E007 — API drill 7: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 7: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #7.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #7, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E008 — API drill 8: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 8: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #8.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #8, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E009 — API drill 9: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 9: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #9.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #9, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E010 — API drill 10: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 10: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #10.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #10, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E011 — API drill 11: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 11: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #11.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #11, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E012 — API drill 12: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 12: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #12.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #12, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E013 — API drill 13: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 13: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #13.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #13, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E014 — API drill 14: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 14: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #14.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #14, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E015 — API drill 15: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 15: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #15.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #15, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E016 — API drill 16: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 16: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #16.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #16, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E017 — API drill 17: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 17: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #17.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #17, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E018 — API drill 18: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 18: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #18.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #18, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E019 — API drill 19: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 19: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #19.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #19, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E020 — API drill 20: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 20: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #20.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #20, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E021 — API drill 21: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 21: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #21.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #21, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E022 — API drill 22: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 22: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #22.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #22, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E023 — API drill 23: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 23: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #23.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #23, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E024 — API drill 24: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 24: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #24.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #24, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E025 — API drill 25: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 25: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #25.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #25, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E026 — API drill 26: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 26: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #26.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #26, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E027 — API drill 27: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 27: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #27.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #27, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E028 — API drill 28: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 28: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #28.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #28, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E029 — API drill 29: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 29: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #29.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #29, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E030 — API drill 30: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 30: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #30.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #30, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E031 — API drill 31: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 31: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #31.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #31, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E032 — API drill 32: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 32: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #32.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #32, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E033 — API drill 33: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 33: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #33.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #33, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E034 — API drill 34: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 34: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #34.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #34, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E035 — API drill 35: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 35: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #35.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #35, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E036 — API drill 36: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 36: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #36.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #36, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E037 — API drill 37: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 37: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #37.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #37, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E038 — API drill 38: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 38: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #38.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #38, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E039 — API drill 39: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 39: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #39.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #39, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E040 — API drill 40: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 40: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #40.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #40, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E041 — API drill 41: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 41: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #41.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #41, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E042 — API drill 42: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 42: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #42.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #42, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E043 — API drill 43: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 43: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #43.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #43, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E044 — API drill 44: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 44: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #44.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #44, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E045 — API drill 45: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 45: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #45.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #45, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E046 — API drill 46: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 46: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #46.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #46, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E047 — API drill 47: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 47: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #47.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #47, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E048 — API drill 48: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 48: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #48.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #48, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E049 — API drill 49: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 49: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #49.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #49, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E050 — API drill 50: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 50: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #50.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #50, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E051 — API drill 51: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 51: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #51.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #51, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E052 — API drill 52: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 52: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #52.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #52, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E053 — API drill 53: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 53: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #53.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #53, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E054 — API drill 54: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 54: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #54.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #54, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E055 — API drill 55: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 55: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #55.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #55, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E056 — API drill 56: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 56: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #56.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #56, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E057 — API drill 57: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 57: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #57.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #57, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E058 — API drill 58: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 58: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #58.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #58, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E059 — API drill 59: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 59: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #59.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #59, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E060 — API drill 60: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 60: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #60.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #60, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E061 — API drill 61: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 61: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #61.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #61, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E062 — API drill 62: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 62: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #62.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #62, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E063 — API drill 63: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 63: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #63.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #63, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E064 — API drill 64: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 64: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #64.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #64, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E065 — API drill 65: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 65: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #65.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #65, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E066 — API drill 66: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 66: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #66.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #66, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E067 — API drill 67: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 67: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #67.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #67, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E068 — API drill 68: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 68: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #68.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #68, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E069 — API drill 69: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 69: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #69.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #69, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E070 — API drill 70: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 70: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #70.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #70, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E071 — API drill 71: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 71: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #71.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #71, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E072 — API drill 72: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 72: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #72.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #72, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E073 — API drill 73: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 73: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #73.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #73, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E074 — API drill 74: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 74: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #74.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #74, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E075 — API drill 75: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 75: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #75.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #75, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E076 — API drill 76: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 76: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #76.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #76, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E077 — API drill 77: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 77: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #77.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #77, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E078 — API drill 78: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 78: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #78.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #78, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E079 — API drill 79: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 79: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #79.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #79, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E080 — API drill 80: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 80: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #80.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #80, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E081 — API drill 81: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 81: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #81.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #81, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E082 — API drill 82: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 82: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #82.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #82, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E083 — API drill 83: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 83: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #83.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #83, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E084 — API drill 84: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 84: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #84.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #84, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E085 — API drill 85: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 85: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #85.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #85, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E086 — API drill 86: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 86: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #86.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #86, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E087 — API drill 87: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 87: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #87.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #87, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E088 — API drill 88: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 88: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #88.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #88, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E089 — API drill 89: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 89: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #89.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #89, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E090 — API drill 90: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 90: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #90.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #90, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E091 — API drill 91: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 91: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #91.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #91, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E092 — API drill 92: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 92: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #92.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #92, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E093 — API drill 93: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 93: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #93.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #93, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E094 — API drill 94: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 94: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #94.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #94, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E095 — API drill 95: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 95: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #95.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #95, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E096 — API drill 96: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 96: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #96.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #96, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E097 — API drill 97: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 97: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #97.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #97, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E098 — API drill 98: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 98: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #98.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #98, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E099 — API drill 99: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 99: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #99.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #99, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E100 — API drill 100: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 100: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #100.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #100, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E101 — API drill 101: Idempotency-Key header for POST /api/payments.
Scenario: Idempotency-Key header for POST /api/payments. (variation 101: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #101.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #101, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E102 — API drill 102: Content-Type negotiation JSON vs msgpack.
Scenario: Content-Type negotiation JSON vs msgpack. (variation 102: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #102.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #102, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E103 — API drill 103: Binary upload > 4.5MB on serverless
Scenario: Binary upload > 4.5MB on serverless — streaming workaround. (variation 103: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #103.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #103, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E104 — API drill 104: HMAC webhook verification constant-time compare.
Scenario: HMAC webhook verification constant-time compare. (variation 104: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #104.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #104, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E105 — API drill 105: Rate limit by API key in Redis sliding window.
Scenario: Rate limit by API key in Redis sliding window. (variation 105: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #105.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #105, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E106 — API drill 106: OpenAPI generation from Zod schemas.
Scenario: OpenAPI generation from Zod schemas. (variation 106: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #106.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #106, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E107 — API drill 107: Versioned URL /api/v2 with sunset headers.
Scenario: Versioned URL /api/v2 with sunset headers. (variation 107: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #107.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #107, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E108 — API drill 108: HEAD request to check existence without body cost.
Scenario: HEAD request to check existence without body cost. (variation 108: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #108.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #108, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E109 — API drill 109: Conditional GET with ETag round trip.
Scenario: Conditional GET with ETag round trip. (variation 109: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #109.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #109, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}
E110 — API drill 110: CORS credentialed requests with wildcard mistake.
Scenario: CORS credentialed requests with wildcard mistake. (variation 110: consider deployment on a serverless platform with regional databases.)
Prompt: Explain trade-offs and what you would measure (latency, error rate, cost) before/after a change for case #110.
Model answer: Start by naming the user-visible symptom (SEO, staleness, TTFB, consistency). List hypotheses (N+1 queries, blocking waterfall, wrong cache directive, missing revalidation). Propose one smallest experiment: add logging/timing, reduce sequential awaits, adjust revalidate window, or move work to background job. Define rollback. For #110, emphasize that measurement beats opinions: compare p50/p95 TTFB and conversion where relevant.
import { NextResponse } from 'next/server';
export async function POST(req: Request) {
const idem = req.headers.get('idempotency-key');
// store idem -> response mapping in Redis with TTL
return NextResponse.json({ ok: true });
}