Welcome to Build and Deploy a REST API with Deno!

Introduction to the newline guide to building and deploying a REST API using Deno.


Welcome to this course, where I will take you from zero to Deno. In this course we will be building a real-life REST API using Deno, a database of your choice, the Oak web framework, and the Nessie database migration tool. This is a beginner's course for a specific usecase in Deno, but no prior knowledge of Deno is required as you will be introduced to everything you need to know. That being said, this is not a course for learning JavaScript, TypeScript or SQL, so if you have no prior knowledge of these, you might have some troubles following along. It might also be good to keep MDN open in another tab for reference.

About the author#

My name is Halvard, and I am a Software Engineer, DevOps and Systems Architect by trade. I have been following the Deno project since 2019, and have created multiple modules for Deno and Node since then. Having worked with Node, and trying to get TypeScript and the latest ES versions incorporated into my code using Babel, I was enthusiastic to discover Deno. As my background comes from building a mountain of REST APIs, I wanted to share my knowledge of Deno using some patterns I have picked up over the years.

About Deno#

Deno brought about a much-needed change in the JavaScript eco system, and is steadily growing its userbase. Since its official version 1.0.0 release in 2020, it has achieved a certain level of maturity. It is also a strong Node contender as can be seen by having almost as may stars on GitHub as Node (Deno: 85k vs Node: 90k), and with the new Node compatibility layer almost every module is available for use out of the box. Deno solves a lot of the headaches Node developers have encountered over the years, and includes integrated tooling such as linter, compiler, bundler, formatter, test-runner andmuch more.

So will Deno take over from Node tomorrow? Most likely not. How about next month? Nah. Then next year? Well, we can always hope, but honestly, Node is probably not going away anytime soon. That being said, Deno is also here to stay, and who knows, maybe in a few months you will start seeing job postings seeking Deno developers with 10+ years' experience. Jokes aside, Deno is already used for some production servers and you can also find them being used for serverless; I have even switched out Python in favor of Deno for Jenkins scripts, and is actively using Deno in my DevOps code.

After following this course you will be able to use Deno to create servers and tools where no npm package is needed. The main portion of this course will be to create a very simple Twitter clone which we will call Quacker (as this is a backend tutorial, we will not be making any frontend for this). This application will incorporate database connections and authentication, and eventually we will place our program on the cloud using a custom Git(Hub|Lab) pipeline.


In this course we're going to be using the following tools:

  • Visual Studio Code (VSCode): I will be using VSCode as my code editor, as there is a Deno plugin for it. You are however free to use the code editor of your choice.

  • Deno: I will install Deno locally, but I will also be demonstrating how to use Docker for development, for those who prefer this. In the last module, I will also show you how to deploy the REST API to DO (Digital Ocean) using a Docker image.

  • Databases: You can choose to install databases locally on your system, but I will use Docker for local development.

  • Docker (optional): As you can see from the tools above, I will utilize Docker, however it is not a mandatory requirement, as you can install the tools locally.

  • Insomnia (Optional): Insomnia is a REST client which will be used to submit requests to the API, but you are free to use any other methods, be it Postman, curl, or the browser.

  • GitLab/GitHub (Optional): In the last module, we will create a deployment pipeline using GitLab and GitHub.

Module 1#

Module 1 will introduce you to Deno. You will learn how to install and use it, either locally, or via Docker. You will be able to follow the rest of the course by using this knowledge, and if you already have some familiarity with Deno, this can serve as a good refresher.

Module 2#

This module will teach you how to connect a Deno application to a database. You will be working with examples using PostgreSQL, MySQL, and SQLite. You will not need to follow along for all of the databases if you are only interested in using one. For the REST API, we will use PostgreSQL, but you should be able to easily reuse the same concept for any of the other databases with some minor adjustments.

Module 3#

In this module, you will learn how to use Nessie for database migrations. We will look at this Deno module in isolation, and you will get a good introduction to how to use it both in a development and production environment with migrations and seeding.

Module 4#

In Module 4 we will take the knowledge obtained in all of the previous modules and build the REST API. You will use Oak as a REST framework, PostgreSQL for the database, and Nessie for migrations. We will also add JWT authentication with an internal user database, and learn how to add middlewares to Oak.

Module 5#

The last module is optional but will teach you how to deploy your code to a cloud provider like Digital Ocean. We will also create a pipeline in GitLab and GitHub and give you an introduction to CI/CD for Deno applications.

Start a new discussion. All notification go to the author.