Welcome to Build and Deploy a REST API with Deno!
Introduction to the newline guide to building and deploying a REST API using Deno.
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.
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 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.
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.
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.
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.
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.