0
0
Expressframework~10 mins

Resource-based URL design 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 define a GET route for retrieving all books.

Express
app.[1]('/books', (req, res) => {
  res.send('List of books');
});
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 retrieving data.
2fill in blank
medium

Complete the code to define a route for retrieving a single book by its ID.

Express
app.get('/books/[1]', (req, res) => {
  const bookId = req.params.id;
  res.send(`Book with ID: ${bookId}`);
});
Drag options to blanks, or click blank then click option'
A*id
Bid
C:id
D?id
Attempts:
3 left
💡 Hint
Common Mistakes
Forgetting the colon before the parameter name.
3fill in blank
hard

Fix the error in the route to update a book by its ID using the correct HTTP method.

Express
app.[1]('/books/:id', (req, res) => {
  res.send(`Updated book with ID: ${req.params.id}`);
});
Drag options to blanks, or click blank then click option'
Aput
Bpost
Cget
Ddelete
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of PUT for updates.
4fill in blank
hard

Fill both blanks to define a route that deletes a book by its ID and sends a confirmation message.

Express
app.[1]('/books/[2]', (req, res) => {
  res.send(`Deleted book with ID: ${req.params.id}`);
});
Drag options to blanks, or click blank then click option'
Adelete
Bpost
C:id
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET or POST instead of DELETE.
Missing colon before the parameter name.
5fill in blank
hard

Fill all three blanks to create a route that adds a new book and sends a success message.

Express
app.[1]('/books', (req, res) => {
  const newBook = req.body;
  // Code to save newBook would go here
  res.status([2]).send('[3]');
});
Drag options to blanks, or click blank then click option'
Apost
B201
CBook added successfully
Dget
Attempts:
3 left
💡 Hint
Common Mistakes
Using GET instead of POST.
Using wrong status code like 200 instead of 201.