Bird
0
0

Which of the following is the correct syntax to send a PUT request with Angular's HttpClient to update a user with id 5?

easy📝 Syntax Q3 of 15
Angular - HTTP Client
Which of the following is the correct syntax to send a PUT request with Angular's HttpClient to update a user with id 5?
Athis.http.put('/api/users/5', updatedUser);
Bthis.http.put('/api/users', updatedUser, 5);
Cthis.http.put('/api/users?id=5', updatedUser);
Dthis.http.put('/api/users', 5, updatedUser);
Step-by-Step Solution
Solution:
  1. Step 1: Understand HttpClient PUT syntax

    PUT method takes URL and data object as parameters. The URL should specify the resource to update.
  2. Step 2: Identify correct URL format

    To update user with id 5, URL should be '/api/users/5'. Passing id as separate argument is incorrect.
  3. Final Answer:

    this.http.put('/api/users/5', updatedUser); -> Option A
  4. Quick Check:

    PUT syntax = url + data object [OK]
Quick Trick: PUT URL targets resource, data is second argument [OK]
Common Mistakes:
MISTAKES
  • Passing id as separate argument
  • Using query params instead of path param
  • Incorrect argument order

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes