Beginnings of an API
We'll explore Oak and it's capabilities in this lesson.
We'll cover the following...
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, inline 1
, and used it to initialize a new Oakapp
, just like we would do with Express, inline 4
. - Then, we logged “Server running at 8000” to the console in
line 6
. - Finally, we allowed our
app
to listen for