Skip to main content
Module

x/cav/endpoints.ts>EndpointSchema

A server framework for Deno
Go to Latest
interface EndpointSchema
import { type EndpointSchema } from "https://deno.land/x/cav@0.0.23/endpoints.ts";

Request processing options for constructing Endpoints.

Type Parameters

optional
GroupsOutput = Record<string, string | string[]>
optional
Ctx = unknown
optional
QueryInput extends Record<string, string | string[]> = (Record<string, string | string[]>)
optional
QueryOutput = Record<string, string | string[]>
optional
MessageInput = unknown
optional
MessageOutput = unknown

Properties

optional
path: string | null

URLPattern string to match against the Request's routed path. If the string starts with '^', the full request path will be used instead. The full URLPattern syntax is supported. Any captured path groups will be merged into the path groups captured during routing. The matched path is available as the "path" resolver argument.

optional
groups: Parser<Record<string, string | string[]>, GroupsOutput> | null

Parses any path groups captured during routing. The result is available as the "groups" resolver argument. If an error is thrown during parsing, the Endpoint won't match with the request and the router will continue looking for matching handlers.

optional
keys: [string, ...string[]] | null

Keys to use when signing cookies. The cookies are available as the "cookies" resolver argument.

optional
ctx: ((c: ContextArg) => Ctx | Promise<Ctx>) | null

Factory function Endpoints can use to create a custom context, which is made available to resolvers as the ctx property on the resolver arguments. Context handling happens after the Endpoint matched with the Request but before input validation begins.

TODO: Example use case

optional
query: Parser<QueryInput, QueryOutput> | null

Parses the query string parameters passed into the URL. If parsing fails, undefined will be parsed to check for a default value. If that also fails, a 400 bad request error will be sent to the client. The output is available as the "query" resolver argument.

optional
maxBodySize: number | null

Limits the size of posted messages. If a message exceeds the limit, a 413 HttpError will be thrown and serialized back to the client. If 0 is specified, body size is unlimited. (Don't do that.) The default max body size is 1024 * 1024 bytes (1 Megabyte).

optional
serializers: Serializers | null

Serializers to use when serializing and deserializing Request and Response bodies.

optional
message: Parser<MessageInput, MessageOutput>

Parses the POSTed body, if there is one. The behavior of this parser determines the methods allowed for this endpoint. If there is no parser, only GET and HEAD requests will be allowed. If there is one and it successfully parses undefined, POST will also be allowed. If the parser throws when parsing undefined, only POST will be allowed. The output from parsing is available as the "message" resolver argument.

optional
resolveError: ((x: ResolveErrorArg) => any) | null

Resolves an error thrown during Endpoint processing into a Response to serve to the client. If no Response is returned, the error will be serialized if it's an HttpError, or a 500 error will be serialized instead if it isn't. If a different error is re-thrown, that error will be serialized instead.