From the course: Angular: Creating and Hosting a Full-Stack Site

Unlock the full course today

Join today to access over 22,400 courses taught by industry experts or purchase this course individually.

Rewrite the listings endpoints

Rewrite the listings endpoints

From the course: Angular: Creating and Hosting a Full-Stack Site

Start my 1-month free trial

Rewrite the listings endpoints

- [Instructor] Now that we have our service set up to connect to the database on startup, and then close that connection when the server is killed, let's move on to seeing how to make actual database queries from our routes. To demonstrate this, what we're going to be doing is rewriting both our getAllListings route and our getListing route to query the database and then send back that data to the client instead of the fake data that we've been using so far. So let's start off with our getAllListings route. The first thing we're going to do here is import the db object that we exported from our database file. So we'll say import db from ../database. And then we're going to modify this route handler here. Instead of returning fakeListings like we've been doing, we're actually going to make a query to our database using the query function of the database object we just imported. So here's what that will look like. We're going…

Contents