Complete the code to define a GET route for retrieving all books.
app.[1]('/books', (req, res) => { res.send('List of books'); });
The get method defines a route to retrieve resources, matching the HTTP GET method.
Complete the code to define a route for retrieving a single book by its ID.
app.get('/books/[1]', (req, res) => { const bookId = req.params.id; res.send(`Book with ID: ${bookId}`); });
Using :id defines a route parameter named id to capture the book's ID from the URL.
Fix the error in the route to update a book by its ID using the correct HTTP method.
app.[1]('/books/:id', (req, res) => { res.send(`Updated book with ID: ${req.params.id}`); });
The put method is used to update an existing resource, matching the HTTP PUT method.
Fill both blanks to define a route that deletes a book by its ID and sends a confirmation message.
app.[1]('/books/[2]', (req, res) => { res.send(`Deleted book with ID: ${req.params.id}`); });
The delete method handles HTTP DELETE requests, and :id captures the book ID from the URL.
Fill all three blanks to create a route that adds a new book and sends a success message.
app.[1]('/books', (req, res) => { const newBook = req.body; // Code to save newBook would go here res.status([2]).send('[3]'); });
POST is used to create new resources. Status code 201 means 'Created'. The message confirms success.