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,800 courses taught by industry experts.
Solution: Creating a remove-from-cart endpoint - React.js Tutorial
From the course: Next.js: Creating and Hosting a Full-Stack Site
Solution: Creating a remove-from-cart endpoint
(upbeat music) - [Instructor] Well, hopefully you've given this Challenge a try. Let's take a look at the Solution. Now, this Solution that I'm going to show you is just one possible way of doing things. So as long as you got kind of close to what I'm going to show you here, that's just great. So the first thing that we had to do, of course, was create a new function in here, to represent this remove from cart endpoint. And as I said, this function was supposed to respond to delete requests. So what I did here is I said, export async function DELETE, all in capital letters. And then I had the same arguments as for the rest of the function. So let me just copy that here to make that a little bit easier. All right, and we're just going to paste that inside of there. And then for the function body, we had to do a lot of similar things to adding to cart. For example, we had to get the user's ID, which we could do by saying, const userID = params.id. And then we had to get the ID of the…
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
-
-
-
-
-