Beginnings of an API

We'll explore Oak and it's capabilities in this lesson.

What is Oak?

Oak is a middleware framework for Deno’s HTTP server, including a router middleware. It’s comparable to Express for Node.js. We’ll use Oak throughout the rest of this course. You can, of course, visit the documentation to read up on it.

Initialising an application

Let’s initialize a new Oak application at port 8000.

Press + to interact
import { Application } from "https://deno.land/x/oak/mod.ts";
const port = 8000;
const app = new Application();
console.log(`server running at ${port}`)
await app.listen({ port });

Alright, so the above code doesn’t run. Don’t panic! We will go over this in a moment. The code looks awfully familiar to Express, right? Let’s break down what we wrote.

  • First, we imported Application from the Oak module, in line 1, and used it to initialize a new Oak app, just like we would do with Express, in line 4.
  • Then, we logged “Server running at 8000” to the console in line 6.
  • Finally, we allowed our app to listen for
...