Building a Restful API — My experience with TrailsJS

Creating a Restful API is not easy: it requires quite a bit of experience in technology but also a good knowledge of the client’s domain. What it also requires is a good framework. Here is my experience with TrailsJS, a modern web application framework for Node.js.

A new API for Humanitarian ID

I went hunting for a framework to create a new API for Humanitarian ID, with the following objectives in mind:

  • Avoid custom code as much as possible: I believe that community checked code will always be more tested and stable than code you write on your own. At least that’s what I think. That’s why I wanted to avoid as much as possible writing custom code, and preferred looking for a framework which I could configure as much as possible before going into coding.

Frameworks compared

I compared quite a few solutions before choosing TrailsJS.

Drupal 8

I come from the Drupal world, my first look therefore went to Drupal 8, which made significant progress in how it can power Restful APIs to create “headless Drupal”. However, customizing the JSON output built by Drupal (which didn’t work for me out of the box) seemed too time consuming.

Other PHP based solutions

The other PHP based solutions I came across all seemed to be part of a big framework, had a steep learning curve and never really seemed designed with “API first” in mind.

Django REST Framework

Django REST Framework could definitely have been a very good choice, and Python is actually a very nice language to write in. It seemed however, that it had a pretty steep learning curve.

Nodejs custom code

I also considered the possibility of writing my API in Nodejs directly using Express or Restify. However, this forced me again to write quite a bit of custom code for my use case

TrailsJS

TrailsJS is a pretty new framework, but it’s based on solid Nodejs components (such as express, mongoose, hapi etc…). It allows you to choose which web server and which ORM you want, and at the same time is quite easy to learn. I therefore decided to use it.

My experience with TrailsJS

I’m writing these lines when the API for Humanitarian ID has already been created. It’s not live yet, but will be soon, and I’ve therefore been using TrailsJS during the last 6 months more or less.

My experience with it has been very positive. I started by creating API endpoints using the footprints module, which allowed me to get very quickly up & running. As the API complexity increased, I removed the footprints to get more control over my endpoints and my code. The configuration files are easy to find, the structure is easy to understand and quite clean. You can also use the existing node modules without any problem.

All in all, the framework has been very pleasant to use, and I would recommend to take a look at it if you ever want to create a Restful API.

Originally published at https://www.gvj-web.com on March 16, 2017.

Développeur web et passionné de finances personnelles

Développeur web et passionné de finances personnelles