Skip to content

Instantly share code, notes, and snippets.

@laiso
Last active July 30, 2022 15:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save laiso/9ca99819b1744a03b812d3553a4e7143 to your computer and use it in GitHub Desktop.
Save laiso/9ca99819b1744a03b812d3553a4e7143 to your computer and use it in GitHub Desktop.
Read a parameter from POST body in Vercel Edge Functions
// 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