I need to share an identical endpoint on two REST API servers in node.

Let's call it `/items`. It's a CRUD-like endpoint, a bit extended with our 
specifics. We also inline apiDoc comments into our routers there so that 
the client devs can also reuse this.

What are some good patterns to keeping those two APIs with their endpoint 
in sync? Currently for us it's a copy-paste job, so naturally it comes out 
of sync on occasion. Due to access restrictions, various consumers can only 
access one or the other.

I was considering two options, and I want a little help.

Shared module version

I'm thinking about a shared repository, but I'm not certain what is a good 
approach there. We have some common, shared endpoints which our various 
APIs and services require, such as data model abstractions, logging, 
utility, but this doesn't exactly fit into one of these.

What would I export from such a module? A self-contained, mountable express 
path would be cool, like:

    import { itemsEndpoint } from 'the-shared-repository';
    app.use('/items', itemsEndpoint({ dbStuff,  utils }));

To me it sounds relatively decent, but could be the downsides? Besides 
having to find a way to keep apiDoc in sync.

Gateway version

Another idea I'm considering is to actually do build a standalone server 
(http, MQ-based, whatever, we're fully into "microservices"), and then use 
my two REST APIs only as pass-through gateways.

Again, I'd also need a way to share apiDoc documentation too here.

I know it's partially opinion-based, but which seems more right or less 
wrong or easier to maintain? I think in the future I might move more of our 
stuff to similar architecture, so I want to get opinion of this esteemed 
forum :D instead of basing the decission my humble, limited thoughts.

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to nodejs@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/nodejs/3e32acb8-afd8-471d-843f-f1e49ed8b800%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to