Bird
0
0

You are designing a REST API for a file storage service. A user tries to access a file:

hard📝 Application Q15 of 15
Rest API - HTTP Status Codes
You are designing a REST API for a file storage service. A user tries to access a file:
GET /files/123

The user is logged in but does not own the file. Which status code should your API return and why?
A401 Unauthorized, because the user must re-authenticate to access the file.
B403 Forbidden, because the user is authenticated but not allowed to access this file.
C404 Not Found, to hide the existence of the file from unauthorized users.
D500 Internal Server Error, because the server cannot process the request.
Step-by-Step Solution
Solution:
  1. Step 1: Determine user's authentication and ownership

    The user is logged in (authenticated) but does not own the file, so lacks permission.
  2. Step 2: Choose correct status code for permission denial

    403 Forbidden is the correct code when the user is authenticated but not allowed to access the resource.
  3. Final Answer:

    403 Forbidden, because the user is authenticated but not allowed to access this file. -> Option B
  4. Quick Check:

    Logged in + no permission = 403 Forbidden [OK]
Quick Trick: Logged in but no access? Return 403 Forbidden [OK]
Common Mistakes:
MISTAKES
  • Using 401 when user is logged in
  • Using 404 to hide resource instead of 403
  • Confusing 500 error with permission issues

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes