I was trying to send a post request to my api. However trying to access the request body in the route handler causes the error below:
Code:
export async function POST(request: Request) {
const postBody: postProps = JSON.parse(request.body) // 👈 Error here on request.body
...
}
Error:
Argument of type ‘ReadableStream’ is not assignable to parameter of type ‘string’.
Any help would be appreciated
2
Answers
I think The issue is just with the Type. Try importing NextApiRequest from next instead of Request
You need to call
json()
on the Request object.