Monday, 25 August 2014

Pondering a RESTful API in Node

Hello!

I am planning to utilise a NodeJS API for my website (gfentimen.com). Before I do this I thought I would try two different API frameworks to see which I prefer.

Loopback vs Express 4
After doing some research into the easiest way to create a RESTful API in node there seem to be a number of challengers. Loopback by StrongLoop seemed to have all the answers, it will connect through to Mongo without an issue, it creates an API framework in next to no time at all, but is it too abstracted?

I downloaded and installed it too see what would happen. Yes - it looks like I am going to have to buy into all of StrongLoops technologies but.... Fair play to them - it was very easy - before I knew I had a screens like these:




So what about Express 4?
Interestingly, since I started writing this blog post Express has had its IP bought by StrongLoop. I hope this will mean more corporate money earmarked for the project. I can't help feeling cynical and suspect that Express will be incorporated into their overcomplicated but admittedly simple to use suite. I can't help feeling that StrongLoop may have missed the point and should instead concentrate on their more evangelical/training pursuits.

I found this article which explains everything extremely well. It feels satisfying because you have such control over every aspect without having to write a colossal amount of code. It was also a relief to find MongoLab and Modulus, I used MongoLab to create my mongo database instance in a matter of minutes.

It gives you the URI e.g. mongodb://<dbuser>:<dbpassword>@ds045087.mongolab.com:45087/gfentimencom

There is an option to create users, however your user account already counts as a user. In other words dbuser and dbpassword are the username and password that you use to set up the MongoLab account NOT a user that you may add through the GUI users option. This had me a little confused for a while and caused some complications connecting to the db.

Another gotcha I has when going through the article it specifies port 8080. The chances are that if you run IIS frequently using this port then you will run into problems like this: events.js 72 throw er eacces.

I took this guys advise and changed my port to 3000 which fixed it. 

I don't think it will come as a surprise to you dear reader that I have gone for Express over Loopback. I found the added sense of control much more satisfying!

No comments:

Post a Comment