Node JS Frameworks for REST APIs

Adam DuVander
Adam DuVander / February 2, 2017

Node JS remains a popular programming language used at companies of all sizes and types: From startups to large enterprises, you’ll find Node’s server-side JavaScript at play. As such, it’s also become a common choice for building APIs. While you don’t need a framework to support a Node-driven API, choosing one can bootstrap the process. With a framework, you can focus simply on how your API accesses and provides data, rather than everything needed to expose those endpoints.

As with any framework, there are tradeoffs based on which one you use. We’ve selected three popular Node JS framework choices (presented alphabetically below), each with a focus on building APIs.

ActionHero: Great for Real-time Services

ActionHero

ActionHero is an API server with a focus on real-time communication capabilities. Due to this focus, it’s built around actions, which can be called from other code, via HTTP (like most APIs), or other protocols. In order to be flexible enough for these different approaches, ActionHero does not enforce a RESTful approach. However, it provides routing functionality that makes ActionHero REST-ready.

Perhaps the largest difference between ActionHero and the others in this post is its built-in queuing. When you add a task to a queue, ActionHero handles the details of removing and processing it in the background. You don’t need to run your own daemon to watch a queue. Plus, timed and delay queues are both supported automatically. These background jobs could be especially useful way to add webhooks to your API.

Overview

GitHub repo: https://github.com/evantahler/actionhero
Forks: ~200
Stargazers: 1,500+
Contributors: 70
NPM downloads: 23,000+ per month

Hapi: Great for Modular Expansion

Hapi

Hapi is an application framework that happens to be very good at creating APIs (it’s in the name, after all). While you can create templated views for web pages using Hapi, by default it does not require it. Hapi’s lightweight approach is also seen in its plugin system for additional functionality.

Within the core framework, there is support for routing, which enables developers to create API endpoints. A route consists simply of a path, a method (HTTP verb), and a handler function. The path can include parameters in {bracket} notation for use within the handler.

Originally, Hapi was a project of Walmart Labs. The lead maintainer no longer works for the company, but there’s good reason to think the major retailer likely depends on Hapi and would continue to support its development. The best part about Walmart’s involvement is you’d have to think Hapi performs well under heavy load.

Overview

GitHub repo: https://github.com/hapijs/hapi
Forks: 750+
Stargazers: 7,000+
Contributors: 151
NPM package downloads: 200,000+ per month

LoopBack: Great for Swagger Support

LoopBack

LoopBack is an API framework built on top of Express, the most popular Web framework for Node. This dependency can be viewed either positively or negatively. While LoopBack has access to the functionality of Express, it also has the overhead of the non-API features of Express, potentially making the codebase more complex.

Among LoopBack’s most intriguing features is its support of Swagger, an API description format now called OpenAPI Specification. Along with exporting and importing descriptions, LoopBack also provides an API Explorer based on Swagger UI.

StrongLoop, the company behind LoopBack, was acquired by IBM in 2015. Aware that big companies can make developers skeptical, IBM has publicly declared its commitment to the project. The fact that StrongLoop’s technology has been incorporated into IBM’s products is a good sign that LoopBack will get the attention it deserves within IBM.

Overview

GitHub repo: https://github.com/strongloop/loopback
Forks: 750+
Stargazers: 8,000+
Contributors: 86
NPM package downloads: 66,000+ per month

How to Choose the Best Node JS API Framework

You’ll be able to build a successful API using any of the three Node JS frameworks mentioned here. All are capable of building RESTful APIs to easily exchange data. Yet they’re different enough that your needs may dictate which to choose.

For example, you might:

  • Choose ActionHero if you want real-time and built-in queuing features.
  • Choose Hapi if you want the basics with modular expansion as needed.
  • Choose LoopBack if you want to generate APIs based off existing descriptions.

The community data mentioned in each section can be useful when considering the popularity and support of a project. This shouldn’t be the only thing you consider, but we’ve tabulated this data (as of early 2017) to help you compare:

FrameworkForksStarsContributorsDownloads / mo
ActionHero2001,5007023,000
Hapi7507,000151200,000
LoopBack7508,0008666,000

Of course, no matter which framework you choose, there are other decisions in making a great API. Chiefly among them is knowing why you are creating the API, so you can help your end users be successful. Once you know that, you just need to get API-powered apps into the hands of your users. We hope the Zapier Developer Platform will be one of the ways you get your API in front of users.


Load Comments...

Comments powered by Disqus