Skip to main content
Module

x/acorn/mod.ts>Serializer

A focused RESTful server framework for Deno 🌰🦕
Go to Latest
interface Serializer
import { type Serializer } from "https://deno.land/x/acorn@0.4.0/mod.ts";

An interface for handling the responses from a route handler in a structured way.

Type Parameters

Params extends Record<string, string>

Methods

optional
stringify(value: unknown): string | Promise<string>

Convert a value returned from a route handler into a JSON string, either synchronously or asynchronously.

If the route handler returns a Response or BodyInit this method will not be called.

If a .toResponse() is provided, this method will not be called.

optional
toResponse(
value: unknown,
params: Params,
request: Request,
): Response | Promise<Response>

A method that takes a value returned from a response handler, along with any parameters parsed when matching the route and the original request, returning a full Response which will be used to respond to the request.

If the route handler returns a Response or BodyInit this method will not be called.

If this method is provided, the .stringify() method will not be called, even if it exists.