I've been experimenting with the new Route API's in Next v13.2, but I'm facing some difficulty in extracting the body values from a POST request.
When calling the API on the client side, my code looks something like this:
const response = await fetch("/api/bot", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({ prompt: "Testing" }),
});
To handle this POST request, I created a file named route.js within the app directory.
Within this file, I defined a function to process the POST request and attempted to retrieve the values from the request object in various ways, without success.
My code snippet looked something like this:
export async function POST(request) {
console.log("Request", request.body.prompt);
return new Response({ response: prompt });
}
Despite multiple tries, I couldn't successfully extract the body values from the request objects.