Skip to main content
Module

x/reno/reno/builtins.ts>withJsonBody

A thin, testable routing library designed to sit on top of Deno's standard HTTP module
Latest
function withJsonBody
import { withJsonBody } from "https://deno.land/x/reno@v2.0.105/reno/builtins.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,
  })
);