Extending Rollbase functionality using Node.js (yes, really!) – Part One

Progress-logo-Rollbase-whitebackground              nodejs

 

In this article, we will cover the architecture of the service as well as set some homework for you to install Node.js

Introduction to Implementing a Node.JS RESTful service

RESTful servers dispatch data for an end point and not a web page. Business logic operates on the backend and your applications are only concerned with CRUD (Create, Read, Update and Delete) operations.

This works nicely with the Rollbase structure – either using Rollbase as the back end, or as the client of the RESTful service. Rollbase has a RESTful API for accessing data within the application and the documentation for this is located here.

This tutorial, however, will focus on Rollbase being the consumer of a service. This may be necessary when some of the data required for your application’s business logic is required to be stored somewhere else and you nee to retrieve or update that data remotely.

Now, when consuming services from within Rollbase, sometimes you have to put a fair amount of code into a Trigger edit window to get what you need. This results in a lot of code inside of Rollbase that you could potentially be broken out and placed in a layer that can not only be used by Rollbase, but by other services as well. Usually this code would be subservient code that is not part of the business logic per se, but provides support mechanisms. Filling up the Trigger code edit window may reduce your ability to read through the business logic.

For example, let’s examine interacting with a third party CMIS based Document Management system such as Alfresco.

To push an uploaded file into the DMS repository, I have to figure out it’s mimetype so I can tell the repo to set the mimetype of the file, build the query and then finally send it off. That’s a lot of code if I put all of that into a Trigger JavaScript edit box – can you image what a mimetype lookup table looks like?

By building a Node.JS based RESTful service, I can leave the bulk of the interaction with the DMS repository to the service, and Rollbase (and other applications) can allow it to do the heavy lifting, with code in Rollbase more focused on the business logic required for the aplication. I just send the RESTful service the content or other data I need it to work with and some parameters around what to do with it.

The benefit of this is that I can make this available to other application platforms as well.

During this tutorial process we will build two architectures.

The first architecture is for an unsecured service. Of course, in the real world you would never want to do this. However in terms of making sure that your functionality works it is a little easier if you don’t have a login prompt sitting in the way.

Our Architecture looks a little like this:

A1-Lge

In our tutorial, The Rollbase installation will be the REST Consumer Client.

Our External Data source will be a CMIS compliant repository. I will be using Alfresco as an example, you should be able to (notwithstanding a minor tweak or two) use any CMIS compliant repository.

Once we are sure our basic functionality works we will hide it behind a Authentication Middleware layer:

A2-Lge

With this architecture, any client which would like to access the data from system should first fire a request to an authentication endpoint with a valid username and a password. The service will then check the validity of the credentials. If ok, it will send a user object back to the client along with an access token.

This token has an expiration time associated with it. The client is expected to send this token to the server everytime a request is made to fetch the data.

As soon as a user makes a call to one of our API endpoints, we redirect the request to the authentication middleware. This middleware is responsible for authenticating the client by first processing the token. If the token is not present, or is invalid (e.g., made up) or expired, it will throw a 401 HTTP ‘Forbidden’ status code. If the request has a valid, unexpired token, we will pass the request to the appropriate call in the application.

Homework: Setup the Node.js Application

The first step in getting this going is obviously to install the Node.js environment. The method to do so may vary depending on the platform you will be running Node.js on – all of which obviously use some kind of download from Node.js – however I have scrounged up a couple of articles that may help. Note that some of these may be out of date by the time you get around to doing this (e.g. a new version of Ubuntu or whatever), so let me know of any updates in the comments so I can update this list:

MacOS X

How to Install Node.js and NPM on a Mac

Windows

How to Install Node.js and NPM on Windows

Ubuntu

How To Install Node.js on an Ubuntu 14.04 server

Centos

How To Install Node.js on a CentOS 7 server

If you have any other OSes articles you wish to share, let me know in the comments and I will update the list above.

Next Article

In the next article, we will cover off the basics of installing the existing libraries we need for Architecture One and as well as why they will be needed. Stay Tuned!

Other Articles in this Series

Extending Rollbase functionality using Node.js (yes, really!) – Part Zero

2 thoughts on “Extending Rollbase functionality using Node.js (yes, really!) – Part One”

Leave a Reply

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