readJson
Reads and parses a JSON request body safely (see parseJsonSafe).
Reads and parses a JSON request body safely (see parseJsonSafe). The body size limit of
the handler already applies to request.
Import#
ts
import { readJson } from "@shadow-js/dusk/server";
Signature#
ts
async function readJson(request: Request): Promise<unknown>
Parameters#
| Name | Description |
|---|---|
request |
The request. |
Returns#
The parsed body.
Throws#
- HttpError 415 when the content type is not JSON or names a charset other than UTF-8 (JSON is UTF-8, RFC 8259), 400 for bytes that are not valid UTF-8, invalid JSON or a forbidden key.
Examples#
ts
export const POST = async ({ request }) => json(await readJson(request));