Multi-File HTTP API Code Review: Methods, Payloads, and Validation
System DesignModel answerLast updated
Audit a multi-file HTTP API to find and fix an incorrect HTTP method, a payload contract mismatch, and missing input validation — then report everything within an hour.
Multi-File HTTP API Code Review
You are given one hour and a set of source files that together implement a small HTTP API. Your task is to review them, identify defects, explain each one by the damage it causes, and either fix it in code or describe the fix precisely enough that a teammate could apply it.
The files span at least a router/controller layer, a service or business-logic layer, and a data or model layer. The known categories of defects are:
- one endpoint is declared with the wrong HTTP method
- the request payload has a contract problem somewhere along the call path
- input is not validated before it reaches business logic or storage
Less obvious defects are likely present too; the review should surface them after the critical ones are handled.
Clarifying questions to ask before you start
Before touching the code, you should ask:
- Are existing clients already calling these endpoints? A method change or payload rename is a breaking change.
- Can I run the code or its tests, or is this read-only?
- What framework and language? How does it parse the request body?
- Is the goal a prioritized list of findings, or deep fixes on the worst issues?
Part 1 — Wrong HTTP method
One endpoint is declared as GET but should be POST.
Explain:
- what concretely breaks while the method stays GET (caching, body stripping, bookmark/retry safety, browser behavior)
- how you identify from the handler code that POST is the right choice
- what a complete fix touches: the route declaration, every caller, the OpenAPI spec or docs, and any tests — plus how to handle existing callers that already use GET
Part 2 — Payload contract mismatch
There is a defect in how the request payload is handled.
Trace a request from the caller through the route handler to the service and model layer and describe:
- where the handler reads request data from, versus where the caller actually sends it
- which mismatches to look for: field names, required vs optional, types, serialization format
- how each kind of mismatch surfaces at runtime — a crash, a silent
null/default, or silently wrong stored data - whether the response payload and status codes are part of the same broken contract
Part 3 — Missing input validation
The API writes or processes user-supplied data without validating it first.
Describe:
- where validation should live in this layered layout and why
- what categories of checks are needed, from basic presence and type checks up to business-rule and size-limit checks
- what the API should return to the caller when validation fails: status code, body shape, field-level detail, and what must not be leaked
- what tests pin this fix
Part 4 — Running the review in one hour
You have several files, one hour, and a trade-off between explaining and fixing.
Explain:
- the reading order that lets you build a mental model of the API before you hunt for bugs
- how you prioritize findings by severity
- when to write a fix versus describe one, and how to verify a fix is complete
- how to narrate each finding so an interviewer or reviewer can follow your reasoning
Hints
Hint 1
For Part 1, ask yourself what HTTP semantics guarantee about GET requests — caching proxies, browser history, retry-on-error — and which of those guarantees break when you send mutation or large-payload requests over GET.
Hint 2
For Part 2, trace the data in one direction end to end: what key does the client JSON use, what key does the handler destructure, what column or field does the model persist? A single rename anywhere in that chain silently drops the value.
Hint 3
For Part 4, start with the entry points (router file, OpenAPI spec, or equivalent) to get a map of every surface before reading any handler in depth — otherwise you spend time on details before you know what the API is supposed to do.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
What a strong answer looks like
Clarifying questions and why they matter
A senior candidate asks before reading a single line:
- Breaking changes? If clients already call
GET /resource, switching toPOSTsilently breaks them. You need a migration plan or a deprecation window. - Runnable? Being able to run tests or
curlthe API changes the review from static reasoning to confirmed evidence. - Framework and body parser? Express parses
req.bodyonly afterexpress.json()is mounted; FastAPI injects a Pydantic model; Rails has strong parameters. The defect pattern differs by framework. - Goal: list or fix? In one hour across multiple files, you usually cannot do both deeply. Confirm the priority.
Part 1 — Wrong HTTP method
What breaks when a mutating endpoint stays GET
HTTP GET is defined as safe and idempotent. That definition has real consequences:
- Caching proxies (CDNs, reverse proxies, browsers) may serve a cached response rather than executing the handler again.
- Many HTTP clients and frameworks strip the request body on GET. If the handler expects
req.body, it receivesundefinedor an empty object silently. - Browsers and load-balancer health checks will retry GET on network failure; retrying a mutation causes duplicate writes.
- Long query strings used as a workaround for the missing body hit URL length limits (roughly 2 KB in many environments).
How you confirm POST is correct
Look at what the handler does: if it creates a record, triggers a side effect, or reads from req.body to do something non-idempotent, it must not be GET. A CREATE or INSERT in the service layer is unambiguous evidence.
What a complete fix touches
- The route declaration:
router.get('/orders', handler)→router.post('/orders', handler). - Every internal caller (other services, scripts, tests) that issues the request.
- The OpenAPI/Swagger spec or equivalent docs — a wrong spec is a bug that lives past the fix.
- Tests: update method in unit and integration tests; add a test asserting GET returns 405.
- Backward compatibility: if external clients already call GET, add a temporary
GEThandler that returns405 Method Not Allowedwith aDeprecationheader and a pointer to the correct method, rather than silently routing them to the wrong behavior.
Part 2 — Payload contract mismatch
Tracing the payload end to end
Draw a chain: caller JSON → HTTP body → framework parser → handler variable → service function argument → model field → stored column. A mismatch at any link breaks the chain.
| Mismatch type | Where it appears | Runtime symptom |
|---|---|---|
Field name typo (userId vs user_id) | Handler ↔ caller | undefined/null stored silently |
| Required field missing in caller | Handler | Crash or default used silently |
Wrong type ("42" vs 42) | Service or DB layer | Type coercion or DB constraint error |
| Camel vs snake case across layers | Any boundary | Silent null or 500 on schema validation |
| Body sent as form-data, parsed as JSON | Framework middleware | Empty req.body |
The response contract is part of the same problem
If the handler returns the created object but uses the wrong field name, the caller cannot read the ID it needs to follow up. Check status codes too: a creation endpoint that returns 200 OK instead of 201 Created is a contract bug even if the data is right.
How to find it
Read the API contract (spec or test fixture) first, then compare it to the handler's destructuring and the model's field definitions. A three-column diff — spec / handler / model — makes every mismatch visible at once.
Part 3 — Input validation
Where validation belongs
Validation should live at the boundary — in the route handler or a middleware that runs before any business logic or write operation. Placing it deeper (in the service or model layer) means invalid data has already traveled further than it should, and error messages have to bubble back up through more layers.
Use a declared schema (Zod, Joi, Pydantic, Yup, JSON Schema, etc.) rather than scattered if (!req.body.email) checks. A schema is readable, testable, and ensures every field is covered.
What to check, in order of severity
- Presence: required fields exist and are not
nullor empty string. - Type:
ageis a number,emailis a string,activeis a boolean — not a stringly-typed version of one. - Format: email matches a pattern, UUID matches a UUID pattern, date is parseable.
- Range and size: string length ≤ limit, number within allowed range, array not unbounded. Unbounded input is a denial-of-service vector.
- Business rules: checked after the above pass, in the service layer (e.g., the referenced foreign key exists).
What to return on failure
- Status
400 Bad Requestfor client-side validation errors. - A consistent body shape:
{ "errors": [{ "field": "email", "message": "must be a valid email address" }] }. - Field-level messages so the caller knows exactly what to fix.
- No stack traces, no internal model names, no DB error strings in the response body.
Tests that pin the fix
- One test per required-field missing.
- One test per type or format violation.
- One test for a completely valid payload, asserting it succeeds.
- One test asserting the error body shape is stable.
Part 4 — Running the review in one hour
Reading order
Start wide, then go deep.
- Router/spec file first (5–10 min): list every endpoint, its method, and its rough purpose. This is your map.
- One complete request path (10–15 min): pick the most critical endpoint and read it from route → handler → service → model in one pass. This reveals the framework patterns and naming conventions used everywhere.
- Systematic pass (30 min): now read the remaining handlers looking for deviations from the pattern you just learned.
- Cross-cutting concerns last (10 min): authentication, authorization, error handling middleware, logging. These are easy to miss when reading individual handlers.
Prioritization
| Severity | Example | Action |
|---|---|---|
| Critical | Wrong method causing duplicate writes; no auth | Fix in code, verify with a test |
| High | Missing validation allowing injection or crash | Fix in code or write a precise spec |
| Medium | Wrong status codes, inconsistent error shapes | Describe with exact line numbers |
| Low | Naming inconsistencies, dead code | Note briefly, do not spend time |
Fix vs describe
Fix it if: the change is small (one route line, one schema file), you can verify it does not break other tests, and fixing it demonstrates you understand the full contract.
Describe it if: the fix requires coordinating across many callers or an external system, or if doing it properly would consume the remaining time.
Narrating findings
Each finding should state: what the code does, what it should do, and what breaks in production if it is not fixed. "Line 42 uses GET but creates a record; a caching proxy will serve a stale 200 and the write will never reach the handler" is more useful to an interviewer than "this should be POST."
Common mistakes to avoid
- Naming the bug without explaining the impact ("it should be POST" with no follow-up).
- Fixing the route but not the tests, spec, or callers — an incomplete fix is a new bug.
- Jumping to the deepest handler first without a map of the API, then running out of time.
- Treating validation as a nice-to-have rather than a security boundary.
- Leaking a DB constraint error directly into the
400response body.