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.
Bookmark API route - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Bookmark API route
So now we're going to implement the bookmark functionality. And basically, what I want to happen is when someone comes to a page and they click this bookmark button, I want it to add the property to their bookmarks array in the database. Because if you remember, in our users, we have this bookmarks array. And then later on, we can put those in the Saved Properties page. So when we click the button, it'll make a request to the API. It'll add it to the database or remove, Because if it's already there, then I want this button to say remove bookmark so they can easily toggle it. So this will take a couple videos, because now I just want to update the field in the database. But then we also want to update the UI to show if it's bookmarked or not, so they can remove and add and so on. So let's start off with the API route. That's usually, if you guys haven't noticed by now, That's usually the route that I like to take, pun intended. So let's go into properties. I'm sorry, not properties…
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)
Geocoding and Mapbox map16m 40s
-
(Locked)
Handle geocode error4m 4s
-
(Locked)
Property page cleanup6m 11s
-
(Locked)
Bookmark API route10m 28s
-
(Locked)
Bookmark button request8m 27s
-
(Locked)
Bookmark status and button toggle8m 54s
-
(Locked)
Saved properties page12m 17s
-
(Locked)
Share buttons10m 41s
-
(Locked)
-
-
-