Question: Now that we have Node.js functions that add data to a database, we want to create API routes that allow us to add and delete

 Now that we have Node.js functions that add data to a

Now that we have Node.js functions that add data to a database, we want to create API routes that allow us to add and delete pets from the database. The first route is a POST request to the path /pet'. The request body will look something like this: { name: 'Charlie', breed: 'Labrador', age: 4, color: 'Tan', } Use the properties in the request body to add a pet record in the database. The second route is a DELETE request to the path '/pet/:id' where 'id' is a path parameter containing the id of the pet record we want to delete. Make sure to call the functions from the petDb module rather than creating new database connections. const express = require('express'); const petDb = require('./petDb'); // our petDB functions from the previous question const app = express(); const port = 3000; app.use(express.json(); // allows us to access the req.body property // add pet routes app.listen(port, () => { console.log('Pet Store app started on port ' + port); }); Feel free to copy the snippet above into your solution

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!