Last active
July 30, 2022 15:20
-
-
Save laiso/9ca99819b1744a03b812d3553a4e7143 to your computer and use it in GitHub Desktop.
Read a parameter from POST body in Vercel Edge Functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// api/post.ts | |
export const config = { | |
runtime: 'experimental-edge', | |
} | |
export default async (req: Request) => { | |
if (req.method !== 'POST') { | |
return new Response('Method not allowed', { status: 405 }); | |
} | |
const result = await req.body.getReader().read(); | |
const body = JSON.parse(new TextDecoder().decode(result.value)) | |
return new Response(JSON.stringify({result: body.test}), { | |
status: 200, | |
headers: { | |
'content-type': 'application/json', | |
} | |
}) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment