KatInterview

Multi-File HTTP API Code Review: Methods, Payloads, and Validation

System DesignModel answer
HardModel answerSystem Designapi-designcode-reviewinput-validation

Last 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.