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

  1. 2.1 REST principles and resource modeling
  2. 2.2 HTTP methods and status codes in API design
  3. 2.3 Filtering, sorting, pagination and field selection
  4. 2.4 Payloads, data formats and error responses
  5. 2.5 Versioning and API evolution
  6. 2.6 API contracts, specifications and documentation
  7. 2.7 API security
  8. 2.8 Rate limits, retries, idempotency and caching
  9. 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

  1. Which URL design follows common REST conventions for fetching one order of a customer?

    1. `POST /orders/fetch` with the IDs in the body
    2. `GET /customers/42/orders/7`
    3. `GET /customer_order_get/42/7`
    4. `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.

  2. Which request would create a new order in a REST API?

    1. `DELETE /orders/new` with the order body
    2. `POST /orders` with the order in the body
    3. `GET /orders/create?item=5&qty=1`
    4. `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.

  3. What is a good way to filter a collection in a REST API?

    1. A JSON request body sent along with the GET
    2. A separate endpoint per filter value, like `/shippedOrders`
    3. A custom HTTP method such as `FILTER /orders`
    4. 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.

  4. What is RFC 9457 "Problem Details" used for?

    1. A log format for recording errors on the server side
    2. A standard JSON shape for errors, with `type`, `title`, `status`
    3. A scheme for encrypting error messages sent to clients
    4. 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`.

  5. Which change is generally backward compatible for API clients?

    1. Making an optional request field required
    2. Changing a field's type from number to string
    3. Renaming an existing response field
    4. 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.

  6. What is consumer-driven contract testing (for example with Pact)?

    1. Checking that the database schema always matches the API's models
    2. Load testing an API by simulating a large number of concurrent consumers
    3. Clients record the interactions they rely on; the provider's build verifies them
    4. 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.

  7. Where should API authorization checks happen?

    1. On the server, for every request and resource
    2. Only at the gateway, never inside the service
    3. Only in the client app, by hiding buttons
    4. 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.

  8. What is rate limiting?

    1. Capping a client's requests per time window to protect the service
    2. Shrinking response bodies so they use less bandwidth
    3. Charging clients a fee for every request they make
    4. 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.

  9. What is an API gateway commonly used for?

    1. One entry point for routing, auth, rate limits and TLS
    2. Replacing the database with an in-memory cache
    3. Storing the API's data in place of a database
    4. 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.

  10. What does HATEOAS mean in REST?

    1. Every response must be HTML rendered for browsers
    2. Every endpoint must support HTTP caching headers
    3. The API version must appear in every single URL
    4. 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.

Practice all 261 questions

More Server Side