0
0
Expressframework~10 mins

HTTP methods for CRUD operations in Express - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to handle creating a new resource using the correct HTTP method.

Express
app.[1]('/items', (req, res) => {
  res.send('Create item');
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST for creating resources.
2fill in blank
medium

Complete the code to handle reading a resource using the correct HTTP method.

Express
app.[1]('/items/:id', (req, res) => {
  res.send('Read item ' + req.params.id);
});
Drag options to blanks, or click blank then click option'
Aget
Bpost
Cput
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of GET for reading data.
3fill in blank
hard

Fix the error in the code by choosing the correct HTTP method to update a resource.

Express
app.[1]('/items/:id', (req, res) => {
  res.send('Update item ' + req.params.id);
});
Drag options to blanks, or click blank then click option'
Aput
Bpost
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST or GET instead of PUT for updating resources.
4fill in blank
hard

Fill both blanks to handle deleting a resource using the correct HTTP method and path.

Express
app.[1]('/items/[2]', (req, res) => {
  res.send('Delete item ' + req.params.id);
});
Drag options to blanks, or click blank then click option'
Adelete
B:id
Cpost
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of DELETE for removing resources.
Missing the ':id' parameter in the path.
5fill in blank
hard

Fill all three blanks to create a full CRUD route for updating an item by ID using Express.

Express
app.[1]('/items/[2]', (req, res) => {
  const id = req.params.[3];
  res.send('Update item ' + id);
});
Drag options to blanks, or click blank then click option'
Aput
B:id
Cid
Dpost
Attempts:
3 left
💡 Hint
Common Mistakes
Using POST instead of PUT for update.
Not including ':id' in the route path.
Incorrect parameter name when accessing req.params.