Issue
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
Solution
You need to call json()
on the Request object.
export async function POST(request: Request) {
const res = await request.json() // res now contains body
}
Answered By - Michael
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.