All jobs / Backend developer / API Development
Backend developer interview question · 0–1 years
The interviewer asks: “What's the difference between HTTP 401 and 403?” Strongest answer?
The strongest answer
401: we don't know who you are — authenticate. 403: we know who you are, and you still may not do this.
Why it works
Exactly. 401 is missing or invalid credentials. 403 is an authenticated caller without permission. Clients branch: sign in vs you can't.
What a good answer covers
- 401 = who are you; 403 = you may not.
- 401: authenticate or refresh the token.
- 403: identity is known; authorization failed.
- Don't wrap either in HTTP 200.
Answers that fall short
- Close, but not the strongest: 401 is login failed; 403 is access denied — two flavours of not allowed.
The labels are close, but 401 is not only a bad password — a missing or expired token is 401 too. 403 means identity is established. - Weak: They are interchangeable. Both mean the request failed; the frontend can show a generic error.
Mixing them hides whether the user should sign in or give up. Gateways and fetch wrappers key off the status. - Red flag: Return 200 with { error: "forbidden" } so the UI never has to handle status codes.
Laundering errors into 200 breaks caches, retries and every HTTP client. Keep the status honest.
Who gets asked this
More API Development questions
- The interviewer asks: “When is 404 the right status, and when is 400?” Strongest answer?
- The interviewer sketches /getOrder and /doDeleteUser. Strongest design?
- The interviewer asks: “Which HTTP methods are safe to retry, and why?” Strongest answer?
- The interviewer asks: “How do you send and read JSON on an HTTP API?” Strongest answer?
- The interviewer asks: “What status do you return when POST creates a resource?” Strongest answer?
- The interviewer asks: “When do you nest URLs like /orders/12/items?” Strongest answer?
- In a GraphQL API, what is the schema and what is a resolver?
- The interviewer asks: “Do you return the database entity as JSON?” Strongest answer?