Bird
0
0

Consider this JavaScript fetch code to delete a post:

medium📝 Debug Q14 of 15
Rest API - HTTP Methods
Consider this JavaScript fetch code to delete a post:
fetch('https://api.example.com/posts/10', {
  method: 'DELETE',
  body: JSON.stringify({ id: 10 })
})
.then(res => res.status)
.then(console.log)

What is the main issue with this code?
AThe URL is incorrect
BDELETE requests should not have a body
CThe method should be GET
DMissing headers for JSON content
Step-by-Step Solution
Solution:
  1. Step 1: Understand DELETE request body rules

    DELETE usually does not require a request body; many servers ignore or reject it.
  2. Step 2: Identify the problem in code

    The code sends a JSON body with DELETE, which is often unnecessary and may cause errors.
  3. Final Answer:

    DELETE requests should not have a body -> Option B
  4. Quick Check:

    DELETE usually no body [OK]
Quick Trick: Avoid sending body with DELETE requests [OK]
Common Mistakes:
MISTAKES
  • Adding unnecessary body to DELETE
  • Confusing method with GET or POST
  • Forgetting to check server docs for DELETE body support

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes