method IRequest.json
IRequest.json<T = unknown>(): Promise<T>

Reads and parses the body as JSON.

Type Parameters

T = unknown

The expected body shape (validate before trusting)

Return Type

Promise<T>

The parsed body

Throws

MalformedRequestBodyError

If the body is not valid JSON. The error carries a 400 HTTP status hint, so an application running errorHandler answers the malformed body with 400 Bad Request in its configured format rather than a masked 500 (X37-1). A handler that catches the rejection keeps full control of what is served.

Usage

import { type IRequest } from "common/src/index.ts";