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.

Update PUT API route

Update PUT API route

All right, guys, we have the Edit page. So if we go to Profile and we click on Edit, we have the form with everything in it. Now we need the API route to submit to. So let's close that up for a minute. And let's create the route. So we'll go to API. And remember, we're using RESTful routes. So to update, it would be API slash properties slash whatever the ID is, right? And it would be a put request. right now, we already have a GET request to this endpoint. We have a DELETE request. So now we need a PUT request. Now, this is going to be pretty similar to the ADD route, which is properties, route.js, and then the POST. So why don't we just copy this? Because that builds the object that we want to submit and everything. And it uploads the image, although we don't need that part. Because remember, this edit form doesn't include images. But we'll copy that whole post route, and then go back into properties ID route.js. Go down to the bottom here, paste that in. And then let's change…

Contents