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

Unlock the full course today

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

Create an individual listing endpoint

Create an individual listing endpoint

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

Start my 1-month free trial

Create an individual listing endpoint

- [Instructor] So far, we've only implemented one route on our server, a route that returns all the listings. And before we move on to actually incorporating an SQL database into our back end, at which point we'll switch our existing routes over to use it as well as create several more, we're going to see how URL parameters work with Hapi servers by creating a route that will allow our front end to request data for individual listings by their IDs. So here's how we do that. First, inside our routes directory, we're going to create a new file called getListing.js. And then inside this file, we're going to create our route. We're going to say import fakeListings from ./fake-data. And then we're going to say export const getListingRoute. And this route is going to listen for the get method on the path /api/listings/{id}. And it's worth noting that in Hapi, We don't use the colon syntax for URL parameters. We instead use curly…

Contents