Basics, methods and statuses
401 means the client is not authenticated and 403 means authenticated but without rights; PUT replaces a resource entirely and PATCH changes some fields. Idempotency concerns the server state, not the response code, so a second DELETE may return 404. A strong short answer has three layers: the definition, the consequence and how an automated test checks it.
API · Interview questions in brief
You are asked about PUT and PATCH, 401 and 403. How do you answer briefly and confidently?
The interviewer asks "PUT or PATCH?", the candidate gives a definition and stops. A pause, the next question, and the talk stays at textbook level. Basic API questions are almost never the goal: they are a way to see in a minute whether practice stands behind the words. This lesson gives an answer template, a table of typical questions with the follow-ups to expect, and a breakdown of two traps.
How an answer works and why
A short answer has three layers. The first, the definition, answers the literal question. The second, the consequence, shows that you understand why it was designed so. The third, the check, moves the talk to your experience: a request, a status, what exactly you compare. The interviewer usually digs from the third layer, so it is better to give it yourself before being asked.
Three layers of an answer
Typical questions and what comes next
| Question | Short answer | The follow-up |
|---|---|---|
| How does client-server architecture work? | The client sends an HTTP request, the server checks authorisation, runs the logic, uses the database and returns a response with a status. HTTP is stateless, so the token goes with every request. | Where is the session kept? Cookie versus token? |
| What is REST? | An API style: data are resources behind URLs, the actions are set by HTTP methods, the server keeps no client state between requests, the format is usually JSON. | How does it differ from GraphQL or gRPC? |
| PUT vs PATCH? | PUT replaces the whole resource and is idempotent. PATCH changes some fields, and its idempotency depends on the format of the change. | What happens to a field missing from a PUT body? |
| What is idempotency? | A repeated identical request does not change the state beyond the first one. GET, PUT, DELETE yes; POST no, so payments need an Idempotency-Key. | The second DELETE returns 404: is that a violation? |
| 401 vs 403? | 401: not authenticated. 403: authenticated but not allowed. | Which status for someone else's order? |
| 400 vs 422? | 400: the request is malformed (broken JSON, a missing field). 422: the shape is fine, but a domain rule is violated. | Does every team draw the line the same way? |
| A 500 on invalid data: is it a bug? | Yes. Invalid input should give a 4xx with an explanation, while 500 means an unhandled failure on the server. | What goes into the bug report? |
Worked example: 401 and 403 in one case
Instead of definitions, show two requests you would really send. A request without a token to a protected resource, and the same kind of request with a regular user's token to an admin action:
GET /api/orders/42 HTTP/1.1
HTTP/1.1 401 Unauthorized
WWW-Authenticate: Bearer
DELETE /api/users/7 HTTP/1.1
Authorization: Bearer <token-of-a-regular-user>
HTTP/1.1 403 Forbidden
The WWW-Authenticate header in a 401 is not decoration: by the HTTP specification such a response has to include it, and the client learns the authentication scheme from it. The second request carried a valid token, so the server knows who it is and refuses by role. Compare two answers to the question:
Two ways to answer about 401 and 403
"401 is no access, 403 is also no access"
Two codes merge into one. The interviewer asks at once: and what should a test do with an expired token?
"Who are you" versus "what may you do"
401: the server does not know who this is (no token, or it expired). 403: it knows, but the role forbids the action. I check both without a token and with a token of another role.
The limits of short answers
- Idempotency. A second
DELETEmay give 404, and that is not a violation: what stays the same is the server state (the resource is gone), not the response code. - PATCH. The instruction "add 10 to the balance" is not idempotent, while "set the balance to 110" is. That is why the table says "depends" for PATCH.
- 400 versus 422. The HTTP specification defines 422 as "the request is understood but its content cannot be processed". Teams draw the line with 400 differently, so a project relies on its contract and requires consistency, not one "correct" code.
- 403 versus 404. To avoid confirming that someone else's resource exists, a server may return 404 instead of 403. That is a deliberate decision, not a mistake.
Common mistakes
- Memorising the table without being able to say "why": the first follow-up exposes it.
- Answering for longer than a minute: the listener loses the thread and the question still has no example.
- Mixing up 401 and 403 in your own tests: a "different user" test expects 401 and masks a missing role check.
- Calling everything "safe" idempotent: safe methods change nothing, while PUT and DELETE do change state but do not change it again on a repeat.
Check yourself
A user sent DELETE /orders/42 twice. The first time 204, the second 404. Is that a violation of idempotency?
Answer
No. Idempotency is about server state: after the first and the second request the resource is gone either way. The response code may differ. It would be a violation if the second DELETE removed something else.
The token has expired. Which status to expect and what does it say about the server?
Answer
401: the server cannot establish the identity because the credentials are not valid. The role is irrelevant here. A 403 would mean the server "knew" the user from an expired token, which is already suspicious.