Skip to main content
Deno 2 is finally here 🎉️
Learn more
Module

x/reno/reno/mod.ts>withJsonBody

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Go to Latest
function withJsonBody
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>>