What’s The Best Restful Web API Framework? – Part 5

by | Nov 28, 2016

Welcome back to Part 5 of the great RESTful framework showdown! Today we are going to do things a bit differently. Previously we have assessed the frameworks against requirements of our final system; security, basic functionality, developer experience, etc.
Today we will be taking a high level look at each framework, what features they offer, and what are the pro’s and con’s of choosing that framework to develop with.

Express.js

Currently considered one of the best way of quickly creating both RESTapi’s and dynamic content webpages through HTML templating, Express.js is one of the most common libraries for Node.js.
Express is a fully featured web framework that allows you to define routes and assign them controller. These controllers can then render pages, return JSON type date, or whatever other things you desire of your API.

Performance

From my own personal experience Express performs well, taking full advantage of Node.js web-first design. Characteristic of any Node.js application Express applications run well on small servers so long as the external network connection of that machine is strong. These web-apps can accept more connections than most other frameworks, and will eventually get around to serving them even on the slowest machine. Even when run on a server with ample power Express will leave the system resources alone until it needs them, allowing you to deploy on a multi-purpose server without worrying about affecting the performance of other applications.

Ease of Development

Express.js (as expected from the name) is one of the quickest frameworks to get up and running with. You have tools like express-generator to seed a project for you (complete with examples), then you define a few methods and your API is running in no time. Being built on Node.js also allows developers not experienced with programming server-side code to use their experience with JavaScript and help out when needed.

Maintainability

One section where Node.js and Express fall short of the competition is maintainability. While JavaScript allows web-developers and designers to contribute to the back-end infrastructure, it comes at a cost. JavaScript is designed to believe the developer in each and every case, trying to continue executing even when something occurred that it did not expect. This means that JavaScript will accept very poorly written code from inexperienced developers that don’t know any better without giving them any feedback that the code they are writing could be better.
This can mean that further down the path for a given web application adding features without breaking older features can become somewhat of a chore. If Node.js and Express is the route for you the best solution is to make sure you have a sound set of development principles and code quality controls and avoid all of these issues.
 

Pros

  • Performs well, even on smaller servers.
  • Quick to get started.
  • Has a number of very good HTML templating systems.
  • Easy for web-developers to adopt.

Cons

  • Can become hard to maintain in large code bases.
  • JavaScript based language, can lead to poor code quality.

Restify

Openly admitting to borrowing heavily from Express.js’s design, restify aims to help developers produce accurate RESTful API’s without worrying about all the other features that Express.js brings along. Bringing easier access to lower level systems and tighter control over latency and performance restify punches well above its lightweight figure.

Performance

Being even more performant than Express, restify slips into the featherweight category. Having no issues handling one connection per week or hundreds in a second resify is the fastest RESTapi framework I have ever dealt with.

Ease of Development

Node.js is the power behind restify just like it is behind Node.js. Though we don’t have a tool like express-generator to help us get started, a basic restify api can be functional (though not interesting) in 5 or so lines of code. Restify takes advantage of being based on Node.js so as we saw with Express.js your web-developers can easily slide into developing new fancy RESTapi’s for all their needs.

Maintainability

We run into the familiar sticking point with JavaScript based frameworks that overtime and without strict controls the code base can become hard to follow and maintain.

Pros

  • Even faster in performance than Express.js.
  • Has access to lower level functionality for those edge cases, and for better control.
  • Quick and easy to get started.

Cons

  • Can become hard to maintain in large code bases.
  • JavaScript based language, can lead to poor code quality.

AWS API Gateway

Most of the frameworks that have a GUI to help creating methods got eliminated early, not AWS API Gateway. While the other GUI tools were eliminated due too being to rigid to a certain way of developing, API Gateway is a way of focusing on just writing code and not worrying about handling those pesky TCP connections. Combined with AWS Lambda you can choose Python, JavaScript (Node.js), Java, or a mix of the three to write methods to handle routes. This offers some of the largest amount of flexibility we have ever seen.

Performance

Performance is hard to measure with API Gateway. While you might notice a slight (very slight in most cases) increase in latency for one isolated method call, with caching and other clever utilities the latency for the next call is the same or faster than a traditional API. Running on AWS Lambda each method call against our API runs in its own little computing instance, giving us free scaling and also more importantly serverless architecture. This means that when no-one is using our API it does not cost us a cent! All in all performance is not an issue at all for API Gateway

Ease of Development

API Gateway can be a little hard to start development with, especially if you are planning on securing your endpoint. With the structure of the API being slightly different you have to pay close attention to the concepts before going ahead in development. Saying that the words used in the UI are as expected for people familiar with API and I had no issues getting started in a reasonable amount of time. Once up and running the ability to write code in separate lambda methods and have a completely modular system allows you to develop anything quickly.

Maintainability

AWS API Gateway allows you to write very modular code with each route contained in a AWS Lambda instance and separated from each other component. This allows you to update sections in isolation from other sections which is great for maintainability. Gateway also can forward requests to other HTTP endpoints so you can use AWS Gateway to slowly migrate an existing API or link multiple API’s under one URL.
 

Pros

  • Very flexible design.
  • Can integrate or extend with existing API’s.
  • Allows the developers to choose the language they want to develop in.

Cons

  • UI can be a little confusing for API newbies.
  • Only available on the AWS platform.

Flask

Flask is the tidy offering from the Python community, and like most other python libraries lends itself to very tidy and readable code. Rather than trying to keep up with the functionality from other big and clunky frameworks like Django, Flask calls itself a ‘micro-framework’ and aims to do a few small things and do them well.

Performance

From my experience Python programs have great performance for an interpreted language, Flask applications are no different. While not being the fastest python web framework it does not make a fool of itself in comparison to the others. It will lose out to Restify and Express on number of concurrent connections in some cases but I can’t even notice these differences in real world tests.

Ease of Development

Flask is the easiest framework to get started with of all its buddies in this test. A basic 1 route API is about 5 lines of code. It’s also 5 lines of very easy to understand and follow code with no crazy new syntax, just buttery smooth Python that we all know (and some of us love).

Maintainability

While also being a dynamically typed language like JavaScript, Python does like to punish you for your error a bit more which leads to better code over a long period of time.

Pros

  • Simple to get started
  • Makes it easy to write very readable code

Cons

  • HTML templating isn’t really there.
  • Missing a few nice to have functions.

Results

So there are a few of the key selling points and drawbacks for the frameworks. Next time will be the last blog in this series where we will write a few basic functions in each API and then decide which API we liked using best!
Coffee to Code – Tim Gray
Tim blogs about the sharp end of code and the languages it is written in.
You can read Tim’s What’s The Best Restful Web API Framework Part 1, Part 2, Part 3, Part 4 and Part 6 to get the whole picture or all of Tim’s blogs here.
We run regular business intelligence courses in both Wellington and Auckland. Find out more here.

0 Comments
Submit a Comment

Your email address will not be published. Required fields are marked *