Complete the code to create a PUT route handler for updating a user.
app.[1]('/user/:id', (req, res) => { // update user logic res.send('User updated'); });
The PUT method is used to update a resource completely. Here, app.put defines the route handler for PUT requests.
Complete the code to create a PATCH route handler for partially updating a user.
app.[1]('/user/:id', (req, res) => { // partial update logic res.send('User partially updated'); });
PATCH is used for partial updates of a resource. Here, app.patch defines the route handler for PATCH requests.
Fix the error in the route handler method to correctly handle a PUT request.
app.[1]('/product/:id', (req, res) => { // update product logic res.send('Product updated'); });
The route must use put to handle PUT requests for updating the product.
Fill both blanks to create a PATCH route that updates only the user's email.
app.[1]('/user/:id', (req, res) => { const newEmail = req.body.[2]; // update email logic res.send('Email updated'); });
The route uses patch for partial update, and email is the field to update from the request body.
Fill all three blanks to create a PUT route that updates a product's name and price.
app.[1]('/product/:id', (req, res) => { const updatedName = req.body.[2]; const updatedPrice = req.body.[3]; // update product logic res.send('Product updated with new name and price'); });
The route uses put for full update, and accesses name and price from the request body to update the product.