Sample questions
Question 1Easy
Which status code best signals that a new resource was created?
- 200 OK
- 202 Accepted
- 201 Created
- 204 No Content
Answer: C. 201 Created
Explanation
201 means a resource was created, often with a Location header pointing to it. 202 means accepted for later processing.
Step-by-step solution
- HTTP status code 201 means a new resource was created.
- This is commonly used after POST requests that create resources.
- The Location header often includes the URL of the new resource.
- Status code 202 indicates acceptance for later processing, not creation.
- The correct answer is 201 Created.
Why the other options are wrong
- A. 200 OK means success in general, but it does not say a new resource was made.
- B. 202 Accepted means the work is queued but not yet done, so no resource is confirmed created.
- D. 204 No Content means success with no body, and it does not signal creation.
Tip: Remember: 201 = Created, 202 = Accepted.
Question 2Easy
Which HTTP method should create a new order in the /orders collection?
- GET
- POST
- DELETE
- HEAD
Answer: B. POST
Explanation
POST to a collection asks the server to create a new member, usually returning 201 with the new resource or its URL.
Step-by-step solution
- Creating a new resource in a collection uses POST.
- POST to /orders creates a new order.
- The correct answer is option B: POST.
Why the other options are wrong
- A. GET reads data and does not create anything.
- C. DELETE removes a resource.
- D. HEAD asks for headers only and does not create anything.
Tip: GET reads, POST creates in a collection, PUT or PATCH changes, DELETE removes.
Question 3Easy
A client sends a request body that is not valid JSON. Which status code should the API return?
- 400 Bad Request
- 500 Internal Server Error
- 200 OK with an error field
- 404 Not Found
Answer: A. 400 Bad Request
Explanation
The fault is in the client's request, so a 4xx code applies. 5xx codes are for server-side failures.
Step-by-step solution
- The request is malformed because the body is not valid JSON.
- 400 Bad Request means the client sent something the server cannot process.
- The correct answer is option A: 400 Bad Request.
Why the other options are wrong
- B. 500 means a server fault, not a bad client request.
- C. A 200 status says the request worked, which is wrong here.
- D. 404 means the resource was not found, not that the body is bad.
Tip: Use 4xx codes for client mistakes and 5xx only for server faults.
Question 4Easy
GET /users/999 is requested but no such user exists. Which status code fits?
- 404 Not Found
- 400 Bad Request
- 500 Internal Server Error
- 403 Forbidden
Answer: A. 404 Not Found
Explanation
404 says the target resource does not exist. 400 is for malformed requests, 500 for server faults.
Step-by-step solution
- GET /users/999 asks for a user that doesn't exist.
- 404 means the requested resource is not found.
- 400 is for invalid request syntax, not missing resources.
- 500 is for server-side errors, not client issues.
- 403 blocks access but doesn't say the resource is missing.
- Final answer: 404 Not Found.
Why the other options are wrong
- B. 400 means the request itself is malformed, not that a valid ID points to nothing.
- C. 500 means the server failed unexpectedly, not that the user was missing.
- D. 403 means the user is known but not allowed; here the user does not exist at all.
Tip: Use 404 for missing pages, 400 for bad requests, and 500 for server errors.
Question 5Medium
Which HTTP method is not idempotent, so a blind retry may create a duplicate?
- POST
- PUT
- DELETE
- GET
Answer: A. POST
Explanation
Repeating a PUT or DELETE leaves the server in the same state, but repeating a POST can create duplicate resources.
Step-by-step solution
- PUT, DELETE and GET leave the same state when repeated.
- POST creates a new resource each time.
- So POST is not idempotent.
Why the other options are wrong
- B. PUT replaces the same resource.
- C. Deleting twice leaves the same state.
- D. GET does not change anything.
Tip: POST is the exception.
Question 6Medium
A sign-up request uses an email address that is already registered (a unique field). Which status code fits best?
- 404 Not Found
- 409 Conflict
- 401 Unauthorized
- 500 Internal Server Error
Answer: B. 409 Conflict
Explanation
409 says the request conflicts with the current state of the resource, such as a duplicate unique key.
Step-by-step solution
- Email is already registered, so request conflicts with existing data.
- HTTP status code 409 indicates conflict in request.
- 409 Conflict is used when a request cannot be completed due to a conflict with the current state.
- This matches the scenario of duplicate email registration.
- Final answer: 409 Conflict.
Why the other options are wrong
- A. 404 means the resource was not found; here the account exists, so the code is wrong.
- C. 401 means the user is not authenticated; a sign-up does not need a login, so 401 does not fit.
- D. 500 means the server failed unexpectedly; a duplicate email is a client-side conflict.
Tip: Use 409 Conflict for duplicate unique fields like emails.
Question 7Medium
A logged-in user requests an admin-only endpoint. Which status code is correct?
- 401 Unauthorized
- 404 Not Found
- 400 Bad Request
- 403 Forbidden
Answer: D. 403 Forbidden
Explanation
401 means the client is not authenticated. 403 means the server knows who the user is but they lack permission.
Step-by-step solution
- 401 means the client is not authenticated.
- 403 means the server knows who the user is but they lack permission.
- The user is logged in, so 401 is incorrect.
- The user lacks admin rights, so 403 is correct.
- Final answer: 403 Forbidden.
Why the other options are wrong
- A. 401 means the client is not authenticated; this user is logged in, so 401 does not fit.
- B. 404 means the resource was not found, but the admin endpoint exists, so the code is 403.
- C. 400 means the request is malformed, and this request is well formed but not allowed.
Tip: Remember: 401 for no auth, 403 for denied access.
Question 8Medium
A client sends If-None-Match with the ETag it cached, and the resource is unchanged. What does the server return?
- 200 OK with the full body again
- 304 Not Modified with no body
- 412 Precondition Failed
- 204 No Content
Answer: B. 304 Not Modified with no body
Explanation
A matching ETag means the cached copy is still valid, so the server saves bandwidth by returning 304.
Step-by-step solution
- If-None-Match sends the ETag the client has cached.
- The server compares it with the current ETag and finds they match, so nothing changed.
- The server replies 304 Not Modified with no body, and the client uses its cached copy. The correct answer is B (304 Not Modified with no body).
Why the other options are wrong
- A. A full body is only sent when the ETag does not match.
- C. 412 is for If-Match checks that fail, not for If-None-Match.
- D. 204 means success with no body, which is not the cache check result.
Tip: ETag plus If-None-Match gives 304 when the content is unchanged; the client saves bandwidth.
Question 9Hard
Why is cursor-based pagination often preferred over page/offset for a large feed that changes constantly?
- Cursors let clients jump straight to any page number
- Offset pagination cannot be used with SQL databases
- Offsets skip or repeat items when rows are inserted
- Cursors avoid the need for any sort order
Answer: C. Offsets skip or repeat items when rows are inserted
Explanation
A cursor marks the last item seen, so new inserts do not shift later pages; it also avoids scanning past large offsets.
Step-by-step solution
- Offset pagination asks for rows like 'skip 20, take 10'.
- If new rows are added at the top while a client pages, the offset points at different rows.
- So items can be skipped or shown twice. Cursors point at a known row, so they avoid this. The correct answer is C (Offsets skip or repeat items when rows are inserted).
Why the other options are wrong
- A. Cursors do not give page numbers; they give the position after the last item seen.
- B. Offsets work fine with SQL databases; the issue is changing data.
- D. Cursor pagination still needs a stable sort order to work well.
Tip: For feeds that change often, paginate with a cursor (last seen id or timestamp), not an offset.
Question 10Hard
Why must a GET endpoint never delete or change data?
- GET requests cannot carry an ID in the URL
- GET is defined as safe, so crawlers and prefetchers call it freely
- Browsers block any response to a GET request that changes server data
- GET responses are too small for confirmations
Answer: B. GET is defined as safe, so crawlers and prefetchers call it freely
Explanation
Caches, link prefetchers and crawlers assume GET has no side effects and may issue it at any time.
Step-by-step solution
- A GET is defined as a safe method: it should only read data.
- Crawlers, link previews and browser prefetching may call GET URLs without the user acting.
- So a GET that changes data can be triggered by accident. The correct answer is B.
Why the other options are wrong
- A. A GET can carry an ID in the URL, as in /items/42.
- C. Browsers do not block GET responses that change data; the problem is the server side effect.
- D. The size of the response has nothing to do with it.
Tip: Use GET only to read. Changes go in POST, PUT, PATCH or DELETE.
Practise all 17 questions free
The full question bank with timed practice, progress tracking and Vidya, your AI tutor. Free, no ads.
Open this topic in the app →