What is oak?

Oak is a middleware framework for DenoA runtime for JavaScript and TypeScript.’s HTTP server that includes a router middleware. It is the most popular choice for backend when it comes to building web applications with Deno.

svg viewer

Oak is inspired by Koa. The middleware router is inspired by @koa/router.

You can import oak in your Deno project using the direct URL:

import {...} from " https://deno.land/x/oak@v4.0.0/mod.ts";

Code

As an example, here’s how a basic HTTP server with oak in Deno looks.

import { Application } from " https://deno.land/x/oak@v4.0.0/mod.ts";
const app = new Application();
app.use((ctx) => {
ctx.response.body = "Hello world!";
});
await app.listen("127.0.0.1:8000");

We import and create an Application class object. Middleware is added via the .use() method. The .listen() method will start the server and begin processing requests with the registered middleware.

You can run the code with Deno using the following command:

$ deno run --allow-net server.ts