From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB

Unlock this course with a free trial

Join today to access over 25,200 courses taught by industry experts.

Fetch single property

Fetch single property

All right, guys. So now we want to fetch a single property from the database. And that's going to be displayed on this page. So the first thing we want to do is create our API route. So let's go to API, our app API. And then in properties, we're going to create a folder called brackets ID, just like we did with the front end page. So in here, we'll create a route.js. So hopefully that makes sense. The convention for front end pages our components is page.jsx. And for API routes, it's going to be route.js. Oh, did I put jsx? I did not mean to do that. Let's rename that to js. Yeah, so that should still work. Honestly, I didn't think that that would even work with jsx, but apparently it does. All right, so in this route.js in the brackets ID, Actually, let's just copy what we have here in this route, paste that in here, because we're still going to need to connect to the database. We're going to need our property model. And then this is going to be slash and then the ID. It's going to…

Contents