Recall & Review
beginner
What is the main difference between PUT and PATCH HTTP methods?
PUT replaces the entire resource with the new data, while PATCH updates only the specified fields of the resource.
Click to reveal answer
beginner
How do you define a PUT route in Express?
Use app.put('/route', (req, res) => { /* handler code */ }); to define a route that handles PUT requests.
Click to reveal answer
beginner
When should you use PATCH instead of PUT in your API?
Use PATCH when you want to update only some fields of a resource without sending the entire object.
Click to reveal answer
intermediate
What happens if you send a PUT request with missing fields compared to the original resource?
The missing fields will be removed or overwritten because PUT replaces the whole resource.
Click to reveal answer
beginner
How can you access the data sent in a PUT or PATCH request in Express?
Use req.body to access the JSON data sent in the request, after using middleware like express.json().
Click to reveal answer
Which HTTP method should you use to update only part of a resource?
✗ Incorrect
PATCH updates only specified fields, while PUT replaces the entire resource.
In Express, which method defines a route for PUT requests?
✗ Incorrect
app.put() handles PUT requests in Express.
What middleware is needed to parse JSON data in PUT or PATCH requests in Express?
✗ Incorrect
express.json() parses JSON request bodies.
If you want to replace a whole user profile, which method is best?
✗ Incorrect
PUT replaces the entire resource.
What happens if a PUT request omits some fields of the resource?
✗ Incorrect
PUT replaces the whole resource, so omitted fields are removed or overwritten.
Explain how to handle PUT and PATCH routes in Express, including how to access the data sent by the client.
Think about how you define routes and get data from requests.
You got /6 concepts.
Describe when you would choose PUT over PATCH and vice versa in a REST API.
Consider how much data you want to send and update.
You got /5 concepts.