REST API Design interview questions

16 questions from the REST API Design: Resources, Status Codes and Security course, each with the correct answer and an explanation. Try to answer before you open the answer.

Module 1: Foundations

1. In a stateless REST API, where should the client's identity/auth info live?

  1. In server-side session memory
  2. Stored in the database and looked up by IP
  3. Sent with every request (e.g. a token in headers)
  4. Hard-coded in the client source code
Show answer

Answer: Sent with every request (e.g. a token in headers)

Statelessness means the server holds no per-client session; the request itself must carry the credentials needed to authenticate it.

Lesson: Statelessness

Module 2: HTTP Basics for APIs

2. A client sends valid JSON, but tries to create a user with an email that already exists. Which status code fits best?

  1. 400 Bad Request
  2. 500 Internal Server Error
  3. 200 OK with an error message
  4. 409 Conflict
Show answer

Answer: 409 Conflict

409 Conflict signals the request is well-formed but clashes with the current state of the resource (a duplicate).

Lesson: HTTP Status Codes

Module 3: Request & Response Design

3. What's the main risk of a top-level API response being a bare JSON array like `[ {...}, {...} ]`?

  1. You can't add metadata (pagination, totals) later without a breaking change
  2. It's slower to parse than an object
  3. JSON doesn't officially support arrays at the top level
  4. It cannot contain nested objects
Show answer

Answer: You can't add metadata (pagination, totals) later without a breaking change

Once clients expect an array, you can't wrap it in an object to add fields like `meta` or `total` without breaking every existing consumer.

Lesson: Field Naming Conventions

Module 5: Versioning

4. Which of these is a *breaking* API change that needs a new version?

  1. Adding a new optional field to the response
  2. Renaming an existing response field
  3. Adding a new endpoint
  4. Fixing a typo in documentation
Show answer

Answer: Renaming an existing response field

Renaming or removing a field breaks any client reading the old name; additive changes like new fields or endpoints are typically safe.

Lesson: Versioning Strategies

Module 6: Authentication & Security

5. Which CORS setting is unsafe with credentialed requests?

  1. Allow-Origin: *
  2. Allow-Origin: a trusted origin
  3. Vary: Origin
  4. Allow-Headers: Authorization
Show answer

Answer: Allow-Origin: *

A wildcard origin lets any site call your API with a user's credentials.

Lesson: HTTPS, CORS & Input Validation

6. A client exceeds its rate limit. What should the API return?

  1. 403 Forbidden
  2. 503 Service Unavailable
  3. 429 Too Many Requests
  4. 200 OK with an empty body
Show answer

Answer: 429 Too Many Requests

429 specifically signals rate limiting, ideally with a Retry-After header telling the client when to try again.

Lesson: Rate Limiting

Module 8: Advanced Concepts

7. A client sends `If-None-Match` with an ETag that still matches the current resource. What should the server return?

  1. 200 OK with the full body
  2. 404 Not Found
  3. 500 Internal Server Error
  4. 304 Not Modified with no body
Show answer

Answer: 304 Not Modified with no body

A matching ETag means the client's cached copy is still valid, so the server confirms freshness with 304 and skips resending the body.

Lesson: Caching with ETags

Module 10: Alternatives to REST

8. A mobile app screen needs a user's profile, their last 3 orders, and their unread notification count in one round trip, with minimal extra data. What fits best?

  1. A single GraphQL query naming exactly those fields
  2. Three separate REST calls
  3. A gRPC streaming call
  4. Polling a SOAP service
Show answer

Answer: A single GraphQL query naming exactly those fields

GraphQL is built for exactly this: one query pulling exactly the needed fields across multiple resources, avoiding both extra round trips and unused data.

Lesson: GraphQL & gRPC

9. Which HTTP method replaces a resource entirely and is idempotent?

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

Answer: PUT

PUT replaces the resource with the supplied body, so repeating it gives the same result.

Lesson: GraphQL & gRPC

10. Which status code fits a successful POST that created a resource?

  1. 200 OK
  2. 204 No Content
  3. 302 Found
  4. 201 Created
Show answer

Answer: 201 Created

201 signals creation and usually includes a Location header.

Lesson: GraphQL & gRPC

11. Why prefer cursor pagination for large changing datasets?

  1. It stays fast and stable under inserts
  2. It lets you jump to page 10
  3. It needs no limit
  4. It avoids sorting
Show answer

Answer: It stays fast and stable under inserts

Cursors avoid slow OFFSET scans and shifting pages.

Lesson: GraphQL & gRPC

12. Which change is breaking and needs a new API version?

  1. Adding an optional field
  2. Renaming a response field
  3. Adding a new endpoint
  4. Improving docs
Show answer

Answer: Renaming a response field

Clients that read the old field name would fail.

Lesson: GraphQL & gRPC

13. Why keep a JWT access token short-lived?

  1. Because it is large
  2. Because it needs a database
  3. Because it cannot be easily revoked
  4. Because it is encrypted
Show answer

Answer: Because it cannot be easily revoked

Short expiry limits damage if a token leaks; refresh tokens renew it.

Lesson: GraphQL & gRPC

14. What should an API return when a client exceeds its rate limit?

  1. 403 Forbidden
  2. 200 OK
  3. 404 Not Found
  4. 429 Too Many Requests
Show answer

Answer: 429 Too Many Requests

429 plus Retry-After helps clients back off.

Lesson: GraphQL & gRPC

15. What does an Idempotency-Key header protect against?

  1. Duplicate processing of retried requests
  2. Slow queries
  3. Cross-site scripting
  4. Large payloads
Show answer

Answer: Duplicate processing of retried requests

The server replays the first result when the same key returns.

Lesson: GraphQL & gRPC

16. What does a matching ETag with If-None-Match return?

  1. 200 with the full body
  2. 304 Not Modified with no body
  3. 404 Not Found
  4. 409 Conflict
Show answer

Answer: 304 Not Modified with no body

The body stays off the wire while freshness is confirmed.

Lesson: GraphQL & gRPC

← Back to the course