From the course: Next.js: Creating and Hosting a Full-Stack Site
Unlock this course with a free trial
Join today to access over 24,500 courses taught by industry experts.
Creating a shopping cart endpoint - React.js Tutorial
From the course: Next.js: Creating and Hosting a Full-Stack Site
Creating a shopping cart endpoint
- [Instructor] Great. So at this point we have route handlers for listing products as well as for loading individual products. So the next route handler that we're going to create is a route handler for sending the user their shopping cart. Now, this one's going to be pretty straightforward, but in order to make sure that you're aware of how these route handlers work in a little bit more detail, we're going to be using a slightly different approach here than what we did previously. So first of all, let's create our shopping cart endpoint, and instead of having this endpoint be inside /api/cart, what we're actually going to do is have it be in /api/users/id/cart. That sounds like a very long path, but you'll see why we're using this very shortly. First, let's just create it though. We'll start off by creating a new folder called users. Then inside there we're going to do an ID folder by saying in square brackets, ID. And then inside that ID folder, we're going to create a new folder…
Contents
-
-
-
-
What are Next.js route handlers?2m 12s
-
How do Next.js route handlers work?7m 29s
-
(Locked)
Testing route handlers with Postman7m 33s
-
(Locked)
Creating a list endpoint for products5m 42s
-
(Locked)
Using route parameters in route handlers8m 10s
-
(Locked)
Creating a shopping cart endpoint9m 5s
-
(Locked)
Creating an add-to-cart endpoint9m 7s
-
(Locked)
Challenge: Creating a remove-from-cart endpoint1m 23s
-
(Locked)
Solution: Creating a remove-from-cart endpoint5m 53s
-
-
-
-
-