Created
January 28, 2024 17:51
-
-
Save davismj/e055ac84692e1f7a3d5c1c1c201b9739 to your computer and use it in GitHub Desktop.
Parse application/x-www-form-urlencoded
This file contains hidden or 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
--- | |
import { parseBody } from 'parse-body' | |
export const partial = true | |
const params = await parseBody(Astro.request.body) | |
--- |
This file contains hidden or 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
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