0
0
Expressframework~5 mins

PUT and PATCH route handling in Express - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
APATCH
BPUT
CGET
DDELETE
In Express, which method defines a route for PUT requests?
Aapp.patch()
Bapp.post()
Capp.get()
Dapp.put()
What middleware is needed to parse JSON data in PUT or PATCH requests in Express?
Aexpress.urlencoded()
Bexpress.json()
Cbody-parser.text()
Dexpress.static()
If you want to replace a whole user profile, which method is best?
AGET
BPATCH
CPUT
DPOST
What happens if a PUT request omits some fields of the resource?
AThose fields are deleted or overwritten
BThe server ignores the request
CThe server returns an error
DThose fields remain unchanged
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.