Bird
0
0

What is wrong with this PUT request code?

medium📝 Debug Q7 of 15
Angular - HTTP Client
What is wrong with this PUT request code?
this.http.put('/api/users', 10, updatedUser).subscribe();
AThe URL should not be a string.
BThe second argument should be the data object, not a number.
Csubscribe() cannot be called without a callback.
DThe data object must be the third argument.
Step-by-Step Solution
Solution:
  1. Step 1: Review HttpClient PUT method signature

    PUT takes URL (string), body (data object), and optionally an options object.
  2. Step 2: Identify incorrect arguments

    Passing 10 as second argument (intended as ID) is wrong; updatedUser should be the second argument (body), with ID in URL like '/api/users/10'.
  3. Final Answer:

    The second argument should be the data object, not a number. -> Option B
  4. Quick Check:

    PUT args = URL + data object [OK]
Quick Trick: PUT: URL first, data second [OK]
Common Mistakes:
MISTAKES
  • Passing extra arguments
  • Misordering arguments
  • Assuming subscribe() must have callback

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Angular Quizzes