REST API design: resources, versioning, pagination and errors – Server Side interview prep
261 interview-style multiple-choice questions on REST API design: resources, versioning, pagination and errors, organized by topic: concepts, scenarios, code to read and tradeoffs, each with a short explanation. Learn the 65 key terms with the flashcards first, then test yourself.
Take the practice test · Flashcards · All study tools
What it covers
- 2.1 REST principles and resource modeling
- 2.2 HTTP methods and status codes in API design
- 2.3 Filtering, sorting, pagination and field selection
- 2.4 Payloads, data formats and error responses
- 2.5 Versioning and API evolution
- 2.6 API contracts, specifications and documentation
- 2.7 API security
- 2.8 Rate limits, retries, idempotency and caching
- 2.9 Async APIs, webhooks, gateways and API styles
Key terms
2.1 REST principles and resource modeling
- Resource
- Something the API exposes, identified by a URL
- HATEOAS
- Hypermedia links in responses that drive client navigation
- Statelessness
- No client session state kept on the server between requests
- Query parameter
- Key-value pair in the URL, often used for filtering
- Uniform interface
- Same rules for all resources
- Richardson Maturity Model
- Levels of REST adoption
- Representation
- One format of a resource's state
- Layered system
- Intermediaries invisible to clients
- Sub-resource
- A resource nested under its parent
2.2 HTTP methods and status codes in API design
- JSON Patch
- List of operations to change a document
- 405 Method Not Allowed
- Method unsupported on this resource
- 415 Unsupported Media Type
- Request body format not accepted
- 412 Precondition Failed
- Condition like `If-Match` didn't hold
- 410 Gone
- Removed on purpose, permanently
2.3 Filtering, sorting, pagination and field selection
- Cursor pagination
- Paging by an opaque marker of the last item seen
- Offset pagination
- Paging by skipping a number of rows
- Problem Details
- Standard JSON error format (RFC 9457)
- JSON Merge Patch
- Partial update format where null removes a field
- Sparse fieldset
- Returning only requested fields
- Keyset cursor
- Encodes the last item's sort keys
- Link header
- Standard links like `rel="next"`
- Delta query
- Fetch only changes since a point
- Tombstone
- Marker for a deleted record
2.4 Payloads, data formats and error responses
- Minor units
- Money as integer cents
- Error code
- Stable machine-readable error identifier
- Presigned URL
- Time-limited direct upload or download link
- NDJSON
- One JSON object per line
- E.164
- International phone number format
- HAL
- Hypermedia JSON with `_links`
2.5 Versioning and API evolution
- Backward compatible
- Existing clients keep working after the change
- Deprecation
- Announcing that a feature will be removed
- Sunset header
- Header giving the date an endpoint will stop working
- Contract testing
- Verifying a provider meets its consumers' expectations
- Media type versioning
- Version in the `Accept` header
- Date-based versioning
- Versions named by release date
- Hyrum's Law
- All observable behavior gets relied on
- Expand and contract
- Add, migrate, then remove
- Brownout
- Scheduled temporary disabling before removal
2.6 API contracts, specifications and documentation
- Design-first
- Write the API spec before the code
- Mock server
- Serves example responses from a spec
- AsyncAPI
- Spec format for event-driven APIs
- Arazzo
- Spec for workflows of API calls
- Spec drift
- Implementation diverging from its spec
- operationId
- Unique name for an operation
2.7 API security
- BOLA
- Missing per-object authorization
- BFLA
- Missing per-operation authorization
- Shadow API
- An exposed API nobody tracks
- Request signing
- Signature over the request's parts
- Restricted key
- API key with limited scopes
- User enumeration
- Learning which accounts exist
2.8 Rate limits, retries, idempotency and caching
- Fixed window
- Count requests per calendar interval
- Leaky bucket
- Steady output rate
- Concurrency limit
- Caps requests in flight
- Hedged request
- Backup request to cut tail latency
- Optimistic concurrency
- Reject writes based on stale versions
2.9 Async APIs, webhooks, gateways and API styles
- OpenAPI
- Standard format for describing HTTP APIs
- Rate limiting
- Capping requests per client over time
- Exponential backoff
- Waiting longer after each failed retry
- Webhook
- Provider-initiated HTTP callback for events
- Long-running operation
- Resource tracking an async job
- Thin event
- Webhook naming a change, not its data
- Standard Webhooks
- Common webhook header spec
- Last-Event-ID
- SSE header for resuming streams
- JSON-RPC
- Method, params and ID over JSON
- tRPC
- Typed TypeScript RPC without a schema
Sample practice questions
Which URL design follows common REST conventions for fetching one order of a customer?
- `POST /orders/fetch` with the IDs in the body
- `GET /customers/42/orders/7`
- `GET /customer_order_get/42/7`
- `GET /getOrderForCustomer?c=42&o=7`
Answer: B. `GET /customers/42/orders/7` Use nouns for resources and let the HTTP method express the action.
Which request would create a new order in a REST API?
- `DELETE /orders/new` with the order body
- `POST /orders` with the order in the body
- `GET /orders/create?item=5&qty=1`
- `PUT /createOrder` with the order in a header
Answer: B. `POST /orders` with the order in the body The server assigns the ID and returns `201 Created` with a `Location` header.
What is a good way to filter a collection in a REST API?
- A JSON request body sent along with the GET
- A separate endpoint per filter value, like `/shippedOrders`
- A custom HTTP method such as `FILTER /orders`
- Query parameters, like `GET /orders?status=shipped`
Answer: D. Query parameters, like `GET /orders?status=shipped` Bodies on GET have no defined meaning and many proxies drop them.
What is RFC 9457 "Problem Details" used for?
- A log format for recording errors on the server side
- A standard JSON shape for errors, with `type`, `title`, `status`
- A scheme for encrypting error messages sent to clients
- A machine-readable format that describes an API's endpoints
Answer: B. A standard JSON shape for errors, with `type`, `title`, `status` Its content type is `application/problem+json`.
Which change is generally backward compatible for API clients?
- Making an optional request field required
- Changing a field's type from number to string
- Renaming an existing response field
- Adding a new optional field to a response
Answer: D. Adding a new optional field to a response Clients should ignore unknown fields so additive changes stay safe.
What is consumer-driven contract testing (for example with Pact)?
- Checking that the database schema always matches the API's models
- Load testing an API by simulating a large number of concurrent consumers
- Clients record the interactions they rely on; the provider's build verifies them
- Asking customers to test every new release by hand before it ships
Answer: C. Clients record the interactions they rely on; the provider's build verifies them It catches breaking changes before deployment.
Where should API authorization checks happen?
- On the server, for every request and resource
- Only at the gateway, never inside the service
- Only in the client app, by hiding buttons
- Only once, at the moment the user logs in
Answer: A. On the server, for every request and resource Missing object-level checks (BOLA) are the top item on the OWASP API Security list.
What is rate limiting?
- Capping a client's requests per time window to protect the service
- Shrinking response bodies so they use less bandwidth
- Charging clients a fee for every request they make
- Limiting how many endpoints an API is allowed to expose
Answer: A. Capping a client's requests per time window to protect the service Token bucket and sliding window are common algorithms.
What is an API gateway commonly used for?
- One entry point for routing, auth, rate limits and TLS
- Replacing the database with an in-memory cache
- Storing the API's data in place of a database
- Compiling the API's code before deployment
Answer: A. One entry point for routing, auth, rate limits and TLS Azure API Management, Kong and AWS API Gateway are examples.
What does HATEOAS mean in REST?
- Every response must be HTML rendered for browsers
- Every endpoint must support HTTP caching headers
- The API version must appear in every single URL
- Responses carry links to related resources and next actions
Answer: D. Responses carry links to related resources and next actions It's part of Fielding's REST constraints but is rarely fully implemented in practice.
More Server Side
- HTTP fundamentals
- GraphQL
- gRPC & real-time APIs
- OAuth 2.0, OIDC & JWT
- Sessions, cookies & web app security
- C# & .NET
- Java & Spring Boot
- Node.js & Express
- Python, Django & FastAPI
- Go (Golang)
- Concurrency & multithreading
- OOP & SOLID
- Design patterns
- Dependency injection
- Logging & observability
- Data structures
- Algorithms & Big-O
- Linux & shell scripting