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
For example - http://domain1/some_endpoint/.
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?
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
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.
I suggest you take a look at Google API node module, it's basically what you are trying to achieve.
Awesome thanks!!!
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.
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).
Yes, this is basically the same general concept I'm trying to achieve. Didn't even know this project existed :)
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.
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
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.
댓글 없음:
댓글 쓰기