Skip to main content
Module

x/oak_middleware/deps.ts>Context

A collection of middleware to use with oak. 🐿️ 🦕
Latest
class Context
import { Context } from "https://deno.land/x/oak_middleware@v0.1.0/deps.ts";

Constructors

new
Context(app: Application<S>, serverRequest: ServerRequest)

Type Parameters

optional
S extends State = Record<string, any>

Properties

app: Application<any>

A reference to the current application

cookies: Cookies

The cookies object

request: Request

The request object

response: Response

The response object

state: S

The object to pass state to front-end views. This can be typed by supplying the generic state argument when creating a new app. For example:

  const app = new Application<{ foo: string }>();

Or can be contextually inferred based on setting an initial state object:

  const app = new Application({ state: { foo: "bar" } });

Methods

assert(
condition: any,
errorStatus?: ErrorStatus,
message?: string,
props?: object,
): asserts condition

Asserts the condition and if the condition fails, creates an HTTP error with the provided status (which defaults to 500). The error status by default will be set on the .response.status.

throw(
errorStatus: ErrorStatus,
message?: string,
props?: object,
): never

Create and throw an HTTP Error, which can be used to pass status information which can be caught by other middleware to send more meaningful error messages back to the client. The passed error status will be set on the .response.status by default as well.