Bird
Raised Fist0

What will be the output of this JavaScript fetch call if the API key is missing?

medium📝 Predict Output Q5 of Q15
Rest API - Authentication and Authorization
What will be the output of this JavaScript fetch call if the API key is missing?
fetch('https://api.example.com/data', {
  headers: { 'Authorization': '' }
})
.then(res => console.log(res.status))
A200
B403
C401
D400
Step-by-Step Solution
Solution:
  1. Step 1: Understand missing API key response

    When the Authorization header is empty, the server treats it as missing credentials and returns 401 Unauthorized.
  2. Step 2: Analyze fetch call output

    The console.log prints the response status, which will be 401.
  3. Final Answer:

    401 -> Option C
  4. Quick Check:

    Missing API key status = 401 Unauthorized [OK]
Quick Trick: Empty Authorization header triggers 401 Unauthorized [OK]
Common Mistakes:
MISTAKES
  • Expecting 403 Forbidden instead of 401
  • Assuming 400 Bad Request for missing key
  • Thinking 200 OK will be returned

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes