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.

Your first API route

Your first API route

OK, so now we're going to start to work on our API routes, because that's where we're going to make our requests from our components to fetch properties, to add, update, delete properties, and so on, and authentication, all that stuff. Anything to do with server-side operations is going to go in the API routes. And the structure for API routes are going to be the same as what we've been doing with the front end. So it's going to go in the app folder, except we're going to have a folder called API. And then whatever we want, like let's say we want slash API slash properties, then we'd create a folder called properties. Now, instead of creating a page.jsx like we would for the front end, we create a route.jsx, OK? And the same rules go for nested routes. Like if you wanted properties slash, I don't know, API slash property slash rooms, then you would create a rooms folder. For single properties, when we want to fetch a single listing, we would have our brackets ID folder, just like we…

Contents