Bird
0
0

A developer wrote this code snippet to delete a resource:

medium📝 Debug Q14 of 15
Rest API - HTTP Methods
A developer wrote this code snippet to delete a resource:
fetch('https://api.example.com/items/10', { method: 'POST' })
  .then(response => console.log('Deleted'));

Why is this code incorrect for an idempotent delete operation?
AThe response is not handled properly
BThe URL is missing a query parameter
CThe fetch method is missing headers
DPOST is not idempotent and should not be used for deletion
Step-by-Step Solution
Solution:
  1. Step 1: Identify the HTTP method used

    The code uses POST to delete a resource, which is incorrect because POST is not idempotent.
  2. Step 2: Understand correct method for deletion

    DELETE method should be used for idempotent deletion, ensuring repeated calls do not cause unintended effects.
  3. Final Answer:

    POST is not idempotent and should not be used for deletion -> Option D
  4. Quick Check:

    DELETE is idempotent, POST is not = A [OK]
Quick Trick: Use DELETE, not POST, for idempotent deletes [OK]
Common Mistakes:
MISTAKES
  • Using POST for delete operations
  • Ignoring HTTP method semantics
  • Assuming POST is idempotent

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Rest API Quizzes