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.

Create an endpoint to get a user listing

Create an endpoint to get a user listing

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

Start my 1-month free trial

Create an endpoint to get a user listing

- [Instructor] So that's the endpoint for adding views to listings. The next endpoint we're going to create is the endpoint for getting all of the current users listings. And this endpoint will be called by the my listings page on our front end. So here's what this is going to look like. Inside our routes directory, we're going to create a new file. And we're going to call it getUserListings.js. And we're going to import our database object from database. And we're going to say export const getUserListingsRoute. And the method for this is going to be GET. The path for this is going to be /api/users/ in curly braces, {userId}/Listings And finally, for the handler, we're going to say async( req, h). And the first thing we're going to do inside this route handler. Is get the userId from the URL parameter. So we're going to say const userId=req.params.userId. And underneath here is where later on, we're going to check…

Contents