Good examples on how to create a library that aggregates REST api's ?

136 views
Skip to first unread message

Justin Maat

unread,
Dec 12, 2014, 11:03:02 PM12/12/14
to nod...@googlegroups.com
Apologies since I know this is sort of a broad question, but I'm fairly new with Node and trying to wrap my head around some best practices.  I come from a java/scala background and while learning a new language, I typically like to look at existing libraries to get some knowledge and understanding.  

My goal - I'm trying to make a npm module that will aggregate a bunch of different (but functionally related) rest api's then expose them with some common wrapper functions.

For example - http://domain1/some_endpoint/..  , http://domain2/some_other_endpoint,..   etc.    Where the endpoints (some_endpoint and other_endpoint) do functionally similar things 

Where my module will allow something like 

var myapp = require('myapp.js');
var Domain1 = myapp.domain1;
var Domain2 = myapp.domain2;


Domain1.endpoint(args);   //or something to this effect
Domain2.endpoint(args);


My question is, what are some open source resources that are considered "good" that I can review for best practices on how to structure the app?  So far, I've looked through the request, async, and q libraries to try and find some inspiration but there seems to be a huge difference in coding styles between alot of these open source projects.


So.. I guess my question can be generalized as - what are some good open source projects that are considered "good" code that can be used for reference?  

Floby

unread,
Dec 15, 2014, 5:51:28 PM12/15/14
to nod...@googlegroups.com
Hello,

my advice on the matter of "good coding style" and "best practices" are that these are similar to bandwagons. The smarter thing to do would be to try and gain some understanding of the existing practices and where they come from.

that said : 
- the node.js codebase itself has a pretty straighforward coding style
- express has had a lot of contributors and does some pretty clever stuff
- I don't like request's coding style and particularily not how it's just one big file
- any of substack's module is a good place to start as they are usually small and easy to wrap your head around
- nodejitsu/flatiron codebases are pretty well done in my opinion, very organised
- strongloop code should be ok to look at as well



On Saturday, 13 December 2014 00:03:02 UTC+1, Justin Maat wrote:
Apologies since I know this is sort of a broad question, but I'm fairly new with Node and trying to wrap my helload around some best practices.  I come from a java/scala background and while learning a new language, I typically like to look at existing libraries to get some knowledge and understanding.  

Justin Maat

unread,
Dec 15, 2014, 6:51:07 PM12/15/14
to nod...@googlegroups.com
Thank you kindly.  This at least helps get me started.  Yeah, I know it's kind of asking for an opinionated answer, but it helps me when I review existing code instead of googling for random snippets across the internet.

I'll start with the actual node codebase and move from there.  

Adrien Risser

unread,
Dec 15, 2014, 8:30:22 PM12/15/14
to nod...@googlegroups.com

I suggest you take a look at Google API node module, it's basically what you are trying to achieve.

--
Adrien Risser, 
Node.js Consultant
+33 6 59 60 32 58

--
Job board: http://jobs.nodejs.org/
New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md
Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
---
You received this message because you are subscribed to the Google Groups "nodejs" group.
To unsubscribe from this group and stop receiving emails from it, send an email to nodejs+un...@googlegroups.com.
To post to this group, send email to nod...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/9c94bbe3-2821-4f02-bb72-8a384a3acbd0%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Justin Maat

unread,
Dec 15, 2014, 10:15:09 PM12/15/14
to nod...@googlegroups.com
Awesome thanks!!!

Yes, this is basically the same general concept I'm trying to achieve.  Didn't even know this project existed :)

Simon Ho

unread,
Dec 26, 2014, 5:21:43 PM12/26/14
to nod...@googlegroups.com
Hi Justin,

Have a look at the LoopBack source code for a good example of a larger project setup. As for REST APIs, this is the perfect use case for actually using LoopBack. You can simply create your models with a few commands and the standard CRUD (create, read, update, delete) REST API endpoints will be created automatically. Of course it does that and a whole lot more, see the documentation for more information.

Cheers,
Simon

Justin Maat

unread,
Dec 26, 2014, 5:46:14 PM12/26/14
to nod...@googlegroups.com
Thanks Simon.  I'm vaguely familiar with LoopBack but I'll have to read a bit more.  This looks better for creating an actual REST api, which I'm not really trying to do.  I'm attempting to wrap existing Rest api's into some common node module.  

Actually the response from Adrien referencing the google project is almost exactly what I'm attempting (except my project isn't related to google's api's).



I'll look more into LoopBack though, seems like a good abstraction for alot of use cases

.

Simon Ho

unread,
Dec 26, 2014, 6:02:50 PM12/26/14
to nod...@googlegroups.com
No problem. Another interesting point to note is that LoopBack provides a REST connector that allows you to do just that (for LoopBack based projects). Basically, it allows you to map REST endpoints to a LoopBack project, which you can use to serve up "new" custom REST endpoints.
Reply all
Reply to author
Forward
0 new messages