In this article we will explore five ways to create a HTTP server with Deno, using the standard library and four packages.
You can find all the code here: https://github.com/tomanagle/deno-http-servers
Note: None of these solutions is a great choice for a brand new application. Deno is not ready for you to risk your job with, so it’s best to wait a while before you start suggesting Deno for your company’s next big project.
The Deno standard library provides a rich set of features that can be used as the building blocks for almost any application. Like most modern programming languages and runtimes, Deno‘s primary use will be web applications, specifically servers that interface over HTTP.
https://github.com/denoland/deno/tree/master/std All PRs and issues should be directed to denoland/deno, not here. We…
The standard library provides a clean and simple way to make a HTTP server. The library alow includes packages for managing cookies.
If you’re not familiar with Deno, there are three things you will notice about the simple HTTP server above:
There’s no package.json, you import files from a link — This is a really cool feature that eliminates the need for a bloated package.json and allows you to do cool things like this:
The await keyword is not inside an async function — Deno has top-level await out of the box, a feature that’s in stage 3 for Node.js.
Run the server: deno run — allow-net — allow-read https://raw.githubusercontent.com/tomanagle/deno-http-servers/master/standard-library.ts
A middleware framework for Deno's net server 🦕. Contribute to oakserver/oak development by creating an account on…
Creating a server with Oak is very simple and the layout is a little bit nicer than the standard library server, mainly because there is no for loop.
Run the server: deno run — allow-net — allow-read https://raw.githubusercontent.com/tomanagle/deno-http-servers/master/oak.ts
Servest is one of the most progressive HTTP module suites for Deno. It has its own implementation of the HTTP/1.1 and allows you to render and server JSX.
🌾A progressive http server for Deno 🌾 Servest is a http module suite for Deno. It is composed of three major APIs of…
Unfortunately, I could not get Servest to render and serve JSX, it may be because my editor didn’t like the syntax. From my experience, being able to render and serve JSX, even HTML from the server is not a feature that is useful in most applications.
Rendering JSX from the server is something that you've been able to do with Express for a long time. Instead, many developers are opting for an entirely different application to handle their client and server-side rendering, such as Next.js.
Furthermore, the handle request looks a lot like Hapi, a Node.js framework that is popular, but not one that I’m particularly thrilled to work with.
While the Servest team has done a great job to get a Deno server out the door very quickly, it feels like more of an experiment than a production-grade server. Experiments are extremely important and have a lot to offer the community, but are not suitable for building companies on.
Run the server: deno run — allow-net — allow-read https://raw.githubusercontent.com/tomanagle/deno-http-servers/master/servest.ts
Abc claims to be a better Deno framework to create web applications. While it is a little bit different, it’s hard to tell why exactly it's better, beyond the cleaner code structure. Like Servest, Abc also provides support for JSX, a feature that might be interesting at first, but I’ve never really found a need for it beyond experimentation.
Abc allows you to chain your routes together from the app method. This style of routing looks nice for small applications, but it may get quite large in more complex scenarios.
Abc also allows you to split the routes off in more of an Express style.
Run the server: deno run — allow-net https://raw.githubusercontent.com/tomanagle/deno-http-servers/master/abc.t
Pogo is inspired by Hapi and encourages reliable, tested application development. It also allows you to render and serve JSX.
Server framework for Deno. Contribute to sholladay/pogo development by creating an account on GitHub.
Like Hapi, Pogo offers a lot of flexibility in the way routing is configured. You can call the server.route method for each endpoint, or pass an array of configuration objects to the server.route endpoint. This helps keep your routes clean and maintainable in large applications.
Run the server: deno run — allow-net https://raw.githubusercontent.com/tomanagle/deno-http-servers/master/pogo.ts
A common these among Deno frameworks is the support for JSX rendering, which I find surprising. It may be that it’s an actual requirement for a lot of projects that I’m not aware of, or it’s an easy way to provide a unique selling point to a framework. If you know what you think in the comments.
So, what would I choose if I was to start a new project with Deno? Firstly, I would only start a new project with Deno right now to test it out and play around. But if I was going to do that, I would start with the standard library and then adopt Oak when the requirements increased.