Bird
0
0

Find the bug in this Node.js fetch example using an API key:

medium📝 Debug Q7 of 15
Rest API - Authentication and Authorization
Find the bug in this Node.js fetch example using an API key:
fetch('https://api.example.com/data', {
  method: 'GET',
  headers: { 'Authorization': 'ApiKey' }
})
.then(response => response.json())
.then(data => console.log(data))
Aresponse.json() is not a valid method
BAPI key value is missing after 'ApiKey' in the Authorization header
Cfetch method should be lowercase 'get'
DHeaders object keys must be lowercase
Step-by-Step Solution
Solution:
  1. Step 1: Check Authorization header content

    The header must include the actual API key after 'ApiKey', but it is missing here.
  2. Step 2: Verify fetch usage

    Method 'GET' is valid uppercase, response.json() is correct, header keys are case-insensitive.
  3. Final Answer:

    API key value is missing after 'ApiKey' in the Authorization header -> Option B
  4. Quick Check:

    Authorization header needs full API key string [OK]
Quick Trick: Include full API key string after 'ApiKey' in headers [OK]
Common Mistakes:
  • Leaving API key value empty
  • Incorrect fetch method casing
  • Misunderstanding response.json() usage

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes