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 - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
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…
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
(Locked)
Create MongoDB database8m 44s
-
(Locked)
MongoDB Compass and importing data4m 36s
-
(Locked)
Database connection and Mongoose6m 31s
-
(Locked)
Your first API route6m 5s
-
(Locked)
Property and user models12m 30s
-
(Locked)
Fetch data using server component9m 48s
-
(Locked)
Requests file4m 25s
-
(Locked)
Fetch single property10m 51s
-
(Locked)
Single property page11m 54s
-
(Locked)
Property details component15m 34s
-
(Locked)
Spinner component2m 37s
-
(Locked)
-
-
-
-
-
-
-