import { withJsonBody } from "https://deno.land/x/reno@v2.0.75/reno/mod.ts";
A higher-order function that takes a route handler function and returns another route handler that parses JSON bodies before invoking the inner handler:
interface PersonRequestBody {
name: string;
}
interface NameLengthResponseBody {
length: number;
}
const getNameLength = withJsonBody<PersonRequestBody>(({ parsedBody }) =>
jsonResponse<NameLengthResponseBody>({
length: parsedBody.name.length,
})
);
Parameters
handler: RouteHandler<JsonRequest<TBody>>