next 14 TS: api get the body data
Answered
Yellowstripe scad posted this in #help-forum
Yellowstripe scadOP
hi! im sending an api request using axios as:
and this is my route file:
i allways get "readable steam", what am i doing wrong?
using APP router if it matter
const response = await axios.post(
'/api/route',
new_user_form_data,
{ headers: { 'Content-Type': 'application/json' } }
);and this is my route file:
import { NextResponse, NextRequest } from 'next/server';
import mongoose_connector from '@/components/db/connections/mongoDB_mongoose_connector';
import UserModel from '@/models/db/user';
export const POST = async (req:NextRequest) => {
try {
await mongoose_connector();
// Parse request body only if it's a ReadableStream
const userData = req.body;i allways get "readable steam", what am i doing wrong?
using APP router if it matter
2 Replies
to get the body of the request do.
const body = await req.json()Answer
@Jesse to get the body of the request do.
ts
const body = await req.json()
Yellowstripe scadOP
Thanks U R AWSOME! broke my head on it for all the day wasted so much time XD