Bird
0
0

What is wrong with this GET request code snippet in JavaScript?

medium📝 Debug Q7 of 15
Rest API - HTTP Methods
What is wrong with this GET request code snippet in JavaScript?
fetch('/users/abc')
  .then(response => response.json())
  .then(data => console.log(data))
  .catch(error => console.error(error));
Assuming user IDs are numeric.
AUsing a string 'abc' instead of numeric ID may cause 404 error
BMissing HTTP method specification in fetch
CResponse.json() is not a function
Dfetch cannot be used for GET requests
Step-by-Step Solution
Solution:
  1. Step 1: Understand fetch usage

    fetch defaults to GET method, response.json() parses JSON body.
  2. Step 2: Identify issue with URL parameter

    User ID 'abc' is invalid if IDs are numeric, likely causing 404 Not Found.
  3. Final Answer:

    Using a string 'abc' instead of numeric ID may cause 404 error -> Option A
  4. Quick Check:

    Invalid ID causes 404 error [OK]
Quick Trick: Use correct ID type in URL to avoid 404 [OK]
Common Mistakes:
  • Assuming fetch needs method for GET
  • Thinking response.json() is invalid
  • Using wrong ID type in URL

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes