Bird
0
0

Identify the error in this POST request code snippet:

medium📝 Debug Q6 of 15
Rest API - HTTP Methods
Identify the error in this POST request code snippet:
fetch('https://api.example.com/data', {
  method: 'POST',
  body: { name: 'test' }
})
AMissing Content-Type header for JSON data
BBody should be a string, not an object
CUsing GET method instead of POST
DURL is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check body format in fetch POST

    Body must be a string, usually JSON string, not a plain object.
  2. Step 2: Identify correct fix

    Use JSON.stringify({ name: 'test' }) to convert object to string.
  3. Final Answer:

    Body should be a string, not an object -> Option B
  4. Quick Check:

    POST body must be stringified JSON [OK]
Quick Trick: Always stringify JSON body in fetch POST requests [OK]
Common Mistakes:
  • Sending raw object instead of JSON string
  • Forgetting Content-Type header
  • Using wrong HTTP method

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes