import * as oak from "https://deno.land/x/oak@v10.5.1/mod.ts";
A middleware framework for handling HTTP with Deno.
oak works well on both Deno CLI and Deno deploy, and is inspired by koa. It works well with both the Deno CLI and Deno Deploy.
Example server
A minimal router server which responds with content on /
. With Deno CLI
this will listen on port 8080 and on Deploy, this will simply serve requests
received on the application.
import { Application, Router } from "https://deno.land/x/oak/mod.ts";
const router = new Router();
router.get("/", (ctx) => {
ctx.response.body = `<!DOCTYPE html>
<html>
<head><title>Hello oak!</title><head>
<body>
<h1>Hello oak!</h1>
</body>
</html>
`;
});
const app = new Application();
app.use(router.routes());
app.use(router.allowedMethods());
app.listen({ port: 8080 });
Classes
Application | A class which registers middleware (via |
Context | Provides context about the current request and response to middleware
functions, and the current instance being processed is the first argument
provided a |
Cookies | An interface which allows setting and accessing cookies related to both the
current request and response. Each |
FormDataReader | An interface which provides an interface to access the fields of a
|
HttpError | The base class for individual classes of HTTP errors. |
HttpServerNative | The oak abstraction of the Deno native HTTP server which is used internally for handling native HTTP requests. Generally users of oak do not need to worry about this class. |
MultiPartStream | A class that takes a file (either a Deno.FsFile or Uint8Array) and bytes and streams the ranges as a multi-part encoded HTTP body. |
NativeRequest | An internal oak abstraction for handling a Deno native request. Most users of oak do not need to worry about this abstraction. |
Request | An interface which provides information about the current request. The
instance related to the current request is available on the
|
Response | An interface to control what response will be sent when the middleware finishes processing the request. |
Router | An interface for registering middleware that will run when certain HTTP methods and paths are requested, as well as provides a way to parameterize parts of the requested path. |
ServerSentEvent | An event which contains information which will be sent to the remote
connection and be made available in an |
Variables
httpErrors | An object which contains an individual HTTP Error for each HTTP status
error code (4XX and 5XX). When errors are raised related to a particular
HTTP status code, they will be of the appropriate instance located on this
object. Also, context's |
REDIRECT_BACK | A symbol that indicates to |
STATUS_TEXT | Map from status code to status text. |
testing.mockContextState | Allows external parties to modify the context state. |
Functions
composeMiddleware | Compose multiple middleware functions into a single middleware function. |
createHttpError | Create a specific class of |
etag.calculate | Calculate an ETag value for an entity. If the entity is |
etag.factory | Create middleware that will attempt to decode the response.body into
something that can be used to generate an |
etag.getEntity | For a given Context, try to determine the response body entity that an ETag can be calculated from. |
etag.ifMatch | A helper function that takes the value from the |
etag.ifNoneMatch | A helper function that takes the value from the |
helpers.getQuery | Given a context, return the |
ifRange | Determine, by the value of an |
isErrorStatus | Determines if a HTTP |
isHttpError | |
isRedirectStatus | Determines if a HTTP |
parseRange | |
proxy | Middleware that provides a back-to-back proxy for requests. |
send | Asynchronously fulfill a response with a file from the local file system. |
testing.createMockApp | Creates a mock of |
testing.createMockContext | Create a mock of |
testing.createMockNext | Creates a mock |
Interfaces
ApplicationOptions | Available options that are used when creating a new instance of
|
BodyContentTypes | |
BodyOptions | Options which can be used when accessing the |
BodyOptionsContentTypes | When setting the |
ByteRange | |
ContextSendOptions | |
CookiesGetOptions | |
CookiesSetDeleteOptions | |
etag.ETagOptions | |
etag.FileInfo | Just the part of |
FormDataBody | When reading a body in full via |
FormDataFile | A representation of a file that has been read from a form data body. Based
on the |
FormDataReadOptions | Options which impact how the form data is decoded for a
|
ListenOptionsBase | |
ListenOptionsTls | |
Middleware | Middleware are functions which are chained together to deal with requests. |
ProxyOptions | |
Route | |
RouterAllowedMethodsOptions | |
RouterContext | The context passed router middleware. |
RouterMiddleware | |
RouterOptions | |
RouterParamMiddleware | Middleware that will be called by the router when handling a specific parameter, which the middleware will be called when a request matches the route parameter. |
SendOptions | |
ServerConstructor | |
ServerSentEventInit | |
ServerSentEventTarget | |
testing.MockContextOptions | Options that can be set in a mock context. |
Type Aliases
BodyBytes | The tagged type for |
BodyForm | The tagged type for |
BodyFormData | The tagged type for |
BodyJson | The tagged type for |
BodyReader | The tagged type for |
BodyStream | The tagged type for |
BodyText | The tagged type for |
BodyType | The type of the body, where: |
BodyUndefined | The tagged type for |
ErrorStatus | A HTTP status that is an error (4XX and 5XX). |
helpers.GetParamsOptions | |
HTTPMethods | |
ListenOptions | |
RedirectStatus | A HTTP status that is a redirect (3XX). |
RouteParams | |
State |