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

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…

Contents