Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

deno
oak
http
web server
definition

What is oak?

Nouman Abbasi

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.

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

RELATED TAGS

deno
oak
http
web server
definition

CONTRIBUTOR

Nouman Abbasi
Copyright ©2022 Educative, Inc. All rights reserved

Grokking Modern System Design Interview for Engineers & Managers

Ace your System Design Interview and take your career to the next level. Learn to handle the design of applications like Netflix, Quora, Facebook, Uber, and many more in a 45-min interview. Learn the RESHADED framework for architecting web-scale applications by determining requirements, constraints, and assumptions before diving into a step-by-step design process.