API Design and Versioning interview questions

29 questions from the API Design and Versioning course, each with the correct answer and an explanation. Try to answer before you open the answer.

Principles of Good API Design

1. Why can you change the code behind an API freely but not its behaviour?

  1. Behaviour is always random
  2. Code is secret and cannot be edited
  3. Clients depend on the contract, so changing behaviour can break them
  4. Because HTTP forbids it
Show answer

Answer: Clients depend on the contract, so changing behaviour can break them

The observable behaviour is the promise; implementation details are private.

Lesson: What Makes an API Good

2. Which URL follows resource-oriented design?

  1. GET /orders/42
  2. GET /fetchOrderNumber42
  3. POST /doDeleteOrder
  4. GET /orders/getById?id=42
Show answer

Answer: GET /orders/42

A plural noun plus an identifier names the resource; the method supplies the action.

Lesson: Resources and URLs

3. Which method is idempotent and replaces a whole resource?

  1. OPTIONS
  2. POST
  3. GET
  4. PUT
Show answer

Answer: PUT

PUT sets the resource to the given representation, so repeating it leaves the same state.

Lesson: HTTP Methods and Their Guarantees

4. Which style suits fast, typed internal service-to-service calls?

  1. Email
  2. gRPC
  3. FTP only
  4. Screen scraping
Show answer

Answer: gRPC

gRPC uses compact Protobuf messages over HTTP/2 with generated typed clients.

Lesson: REST, GraphQL, gRPC and Webhooks: Choosing a Style

Requests, Responses and Errors

5. A user is logged in but lacks permission for an action. Which code fits?

  1. 401 Unauthorized
  2. 403 Forbidden
  3. 200 OK
  4. 500 Internal Server Error
Show answer

Answer: 403 Forbidden

The identity is known but not allowed, which is 403.

Lesson: Choosing Status Codes

6. Why give every error the same JSON shape?

  1. JSON requires it
  2. It hides the status code
  3. It makes responses longer by design
  4. Clients can handle all failures with one parser and logic
Show answer

Answer: Clients can handle all failures with one parser and logic

Predictable errors reduce client code and make failures easy to log and search.

Lesson: Error Responses: Problem Details

7. Why is cursor pagination more stable than offset pagination?

  1. It continues after the last seen item, so inserts or deletes do not shift pages
  2. It uses random numbers
  3. It returns every row at once
  4. Offsets are illegal
Show answer

Answer: It continues after the last seen item, so inserts or deletes do not shift pages

A position anchored to an item survives changes elsewhere in the list.

Lesson: Pagination: Offset vs Cursor

8. What does `?sort=-created_at` conventionally mean?

  1. Sort ascending
  2. Delete created_at
  3. Sort by created_at descending
  4. Hide created_at
Show answer

Answer: Sort by created_at descending

A leading minus is a common convention for descending order.

Lesson: Filtering, Sorting and Field Selection

Reliability and Performance

9. What does a server do when it receives a repeated Idempotency-Key with the same request?

  1. Deletes the first result
  2. Performs the action again
  3. Returns the stored result without repeating the action
  4. Crashes
Show answer

Answer: Returns the stored result without repeating the action

The key links retries to the original attempt so the side effect happens once.

Lesson: Idempotency Keys

10. What does `304 Not Modified` tell the client?

  1. The cached copy is still valid; no body is sent
  2. The resource was deleted
  3. The request failed
  4. Credentials are wrong
Show answer

Answer: The cached copy is still valid; no body is sent

A conditional GET with a matching ETag lets the server skip the body.

Lesson: Caching and Conditional Requests (ETag)

11. Which status and header tell a client to wait?

  1. 301 with Location
  2. 200 with Content-Length
  3. 404 with ETag
  4. 429 with Retry-After
Show answer

Answer: 429 with Retry-After

429 says "too many requests" and Retry-After says when to try again.

Lesson: Rate Limiting and Quotas

12. What should an API return for a request that will take minutes to finish?

  1. 200 after blocking for minutes
  2. 202 Accepted with a Location for a status resource
  3. 204 and forget it
  4. 401
Show answer

Answer: 202 Accepted with a Location for a status resource

Acknowledge quickly and let the client check progress separately.

Lesson: Long-Running Operations and Bulk Requests

Security and Trust

13. Where should an access token be sent?

  1. In the URL query string
  2. In the Authorization header over HTTPS
  3. In the page title
  4. In a public repository
Show answer

Answer: In the Authorization header over HTTPS

Headers over TLS avoid leaking credentials into logs and history.

Lesson: Authentication and Authorisation

14. What does BOLA stand for and what is the flaw?

  1. A JSON format
  2. Better Online Load Analysis
  3. A caching feature
  4. Broken object-level authorisation: accessing others' objects by changing an ID
Show answer

Answer: Broken object-level authorisation: accessing others' objects by changing an ID

The server must check ownership of each object, not only that the user is logged in.

Lesson: Object-Level Authorisation and Data Exposure

15. Why include a timestamp in the signed data?

  1. To reject old, replayed messages
  2. To make the body smaller
  3. Because HMAC requires dates
  4. To speed up delivery
Show answer

Answer: To reject old, replayed messages

Without freshness, an attacker could resend a captured valid message later.

Lesson: Webhooks: Signing and Verifying

Versioning and Evolution

16. Which change is breaking?

  1. Adding a new endpoint
  2. Adding a new optional response field
  3. Removing a field from a response
  4. Adding an optional query parameter
Show answer

Answer: Removing a field from a response

Existing clients may read the removed field, so its removal breaks them.

Lesson: What Counts as a Breaking Change

17. What is a main advantage of URI versioning?

  1. It needs no documentation
  2. It hides the version completely
  3. The version is visible and easy to route, cache and test
  4. It is invisible to proxies
Show answer

Answer: The version is visible and easy to route, cache and test

Putting the version in the path makes it explicit in logs, links and tools.

Lesson: Versioning Strategies

18. Which header should be added when the response depends on Accept?

  1. Vary: Accept
  2. Content-Length: 0
  3. Retry-After
  4. Location
Show answer

Answer: Vary: Accept

Vary tells caches the response differs by the Accept header, avoiding the wrong copy being served.

Lesson: Content Negotiation and the Accept Header

19. Why keep one internal model for several API versions?

  1. It removes the need for tests
  2. It forces clients to upgrade
  3. Multiple models are always required
  4. Features and fixes are implemented once and exposed through version-specific serialisers
Show answer

Answer: Features and fixes are implemented once and exposed through version-specific serialisers

Thin translation layers limit duplication while old and new shapes coexist.

Lesson: Running v1 and v2 Side by Side

Deprecation and Migration

20. Which header gives the date after which a resource may stop working?

  1. ETag
  2. Sunset
  3. Vary
  4. Location
Show answer

Answer: Sunset

Sunset (RFC 8594) announces the retirement date; Deprecation marks the resource as deprecated.

Lesson: Deprecation and Sunset Headers

21. What should a retired endpoint return after its sunset date?

  1. 200 with empty data
  2. 410 Gone with a helpful problem body
  3. A random 500
  4. Nothing, close the connection
Show answer

Answer: 410 Gone with a helpful problem body

410 clearly states the resource is permanently gone and can point to migration help.

Lesson: Timelines, Communication and Usage Tracking

22. Why compare old and new responses in shadow mode?

  1. To delete data
  2. To double the bill
  3. To avoid testing
  4. To find differences before users are affected
Show answer

Answer: To find differences before users are affected

Shadow traffic reveals behavioural mismatches without risking production users.

Lesson: Compatibility Layers and Gradual Migration

Contracts, Testing and Governance

23. What is a benefit of designing the OpenAPI contract first?

  1. Teams can review, mock and generate code before implementing
  2. It removes the need for any code
  3. It makes APIs slower
  4. It prevents all bugs
Show answer

Answer: Teams can review, mock and generate code before implementing

A shared, reviewable contract aligns producers and consumers early.

Lesson: Contract-First with OpenAPI

24. What does a CI breaking-change check do?

  1. Deletes old versions
  2. Deploys to production
  3. Compares the new spec with the released one and flags incompatible changes
  4. Encrypts the spec
Show answer

Answer: Compares the new spec with the released one and flags incompatible changes

Automatic diffing stops accidental breaking changes from reaching users.

Lesson: Testing the API and the Contract

25. What is the aim of API governance?

  1. To remove documentation
  2. To slow down all releases
  3. Consistent, high-quality APIs across teams without blocking delivery
  4. To avoid versioning forever
Show answer

Answer: Consistent, high-quality APIs across teams without blocking delivery

Shared standards and light review keep APIs coherent and easy to adopt.

Lesson: Documentation, SDKs and API Governance

Putting It Together

26. Which production concerns does the demo server deliberately omit?

  1. Authentication, persistence and concurrency control
  2. HTTP status codes
  3. JSON responses
  4. All headers
Show answer

Answer: Authentication, persistence and concurrency control

It teaches API behaviour, so real deployments must add security and storage.

Lesson: Case Study: A Payments and Items API

27. A mobile app retries `POST /payments` after a timeout and the customer is charged twice. What is the best fix?

  1. Return 200 for every error
  2. Disable retries on the client only
  3. Switch the endpoint to GET
  4. Require an Idempotency-Key and replay the stored result for repeats
Show answer

Answer: Require an Idempotency-Key and replay the stored result for repeats

The key ties retries to one logical operation so the charge happens once.

Lesson: Revision: Cheat Sheet and Self-Check

28. You must rename a response field used by thousands of clients. What is the safest plan?

  1. Rename it and hope
  2. Add the new field alongside the old one, deprecate the old with a sunset date and track usage
  3. Remove it silently next release
  4. Change its meaning but keep the name
Show answer

Answer: Add the new field alongside the old one, deprecate the old with a sunset date and track usage

Additive change plus a deprecation period lets clients migrate on their own schedule.

Lesson: Revision: Cheat Sheet and Self-Check

29. A client requests page 2 after rows were inserted at the front of the list. Which pagination avoids duplicates?

  1. Offset pagination
  2. Cursor (keyset) pagination
  3. Random pagination
  4. No pagination
Show answer

Answer: Cursor (keyset) pagination

A cursor continues after the last seen item, regardless of inserts earlier in the list.

Lesson: Revision: Cheat Sheet and Self-Check

← Back to the course