Bird
0
0

Identify the error in this Angular DELETE request code:

medium📝 Debug Q14 of 15
Angular - HTTP Client
Identify the error in this Angular DELETE request code:
this.http.delete('api/items').subscribe(response => {
  console.log('Item deleted');
});

Assuming the API requires an item ID to delete a specific item.
ADELETE requests cannot be sent without a request body
BThe URL is missing the item ID to specify which item to delete
CThe subscribe method is missing a parameter
DThe console.log statement is incorrect
Step-by-Step Solution
Solution:
  1. Step 1: Check the URL for DELETE request

    The URL 'api/items' does not specify which item to delete; an ID is needed.
  2. Step 2: Understand API requirements

    APIs usually require an ID in the URL like 'api/items/1' to delete a specific item.
  3. Final Answer:

    The URL is missing the item ID to specify which item to delete -> Option B
  4. Quick Check:

    DELETE URL needs item ID = C [OK]
Quick Trick: DELETE URL must include resource ID to delete [OK]
Common Mistakes:
MISTAKES
  • Sending DELETE without specifying resource ID
  • Thinking DELETE needs a request body
  • Ignoring subscribe callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes