Complete the code to create a simple GET endpoint using Express that returns a welcome message.
app.[1]('/welcome', (req, res) => { res.send('Welcome to our API!'); });
The GET method is used to request data from a server. Here, it defines an endpoint that sends a welcome message.
Complete the code to parse JSON request bodies in Express using middleware.
app.use([1].json());Express has built-in middleware called express.json() to parse JSON bodies from incoming requests.
Fix the error in the route handler to correctly send a JSON response with a status code.
app.get('/data', (req, res) => { res.status([1]).json({ message: 'Data fetched' }); });
The status code should be a number, not a string. 200 means success.
Fill both blanks to create a RESTful route that updates a user by ID using the correct HTTP method and URL pattern.
app.[1]('/users/[2]', (req, res) => { // update user logic res.send('User updated'); });
PUT is used to update resources. The URL uses a parameter :id to specify which user to update.
Fill all three blanks to create a RESTful DELETE route that removes a product by its ID and sends a confirmation message.
app.[1]('/products/[2]', (req, res) => { const productId = req.params.[3]; // delete product logic res.send(`Product ${productId} deleted`); });
DELETE method removes resources. The URL uses :id as a parameter. The handler accesses req.params.id to get the ID.