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.
Add property POST API route - Next.js Tutorial
From the course: Next.js 14 from Scratch: Build a Real-World Project Using Next.js 14 and MongoDB
Add property POST API route
So now that we have our form set with the change handlers, we need to handle the submission. All right, now there's a few ways we can submit. We could add an on submit and do it that way, or we could just simply add an action and a method to the form tag, which is the route that I'm going to take in this video, in this form. So let's come down to the form tag, And let's add to that an action. And for that, we're going to set that to slash API slash properties. We're using RESTful routes. So basically, we'll make a POST request to API slash properties. And that will be to create a new property. And then we want the method. So the method is going to be POST. And then since there's an image field, So we need to add an ink type, and we're going to set that to multi-part slash and then form dash data. That will allow us to upload an image or images. Now for the route, we're going to go to our app slash API slash properties. And we already have a route.js here with a get. Now what we need…
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.