Skip to content

Instantly share code, notes, and snippets.

@davismj
Created January 28, 2024 17:51
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 davismj/e055ac84692e1f7a3d5c1c1c201b9739 to your computer and use it in GitHub Desktop.
Save davismj/e055ac84692e1f7a3d5c1c1c201b9739 to your computer and use it in GitHub Desktop.
Parse application/x-www-form-urlencoded
---
import { parseBody } from 'parse-body'
export const partial = true
const params = await parseBody(Astro.request.body)
---
const decoder = new TextDecoder('utf-8')
export async function parseBody(body: ReadableStream<Uint8Array>): Promise<Record<string, string>> {
const { value } = await body.getReader().read()
const decoded = decoder.decode(value)
const params = new URLSearchParams(decoded)
return Object.fromEntries(params.entries())
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment