dashersw / cote

A Node.js library for building zero-configuration microservices.
http://cote.js.org
MIT License
2.34k stars 188 forks source link

Is there something of http gateway? #137

Open zhaoyao91 opened 5 years ago

zhaoyao91 commented 5 years ago

Cote is great, but the communications are enclosed in its own system. Other apps of different framework or language are difficult to chat with them.

Is there or planning to build an out-of-box http gateway component to proxy the in-out communications?

dashersw commented 5 years ago

Hi! In fact there was a pull request earlier to streamline this — #27. However we weren't satisfied with the API and stopped working on it. I'd love to help more contributors on this.

mikield commented 5 years ago

I think that out of the box API gateway is not needed. It's based on application.

For example, my app doesn't not use API Gateway, I am using cote for my many-platforms chat bot.

robodude666 commented 5 years ago

I'm with @mikield on this.

I don't know how much value an out-of-the-box http gateway would add. You'd likely want some sort of auth/middleware in the mix or ability to customize the end points, perform validation, etc.

Users are better off taking their favorite REST framework and building a wrapper around a Requester.

dashersw commented 5 years ago

That’s right. That’s also partially why we didn’t merge this. However, cote could still provide an easier interface for —for example— Express apps to hook into. Currently it requires a lot of boilerplate that gets repetitive and error prone.

robodude666 commented 5 years ago

How much simpler could you get than this?

app.get('/product', function(req, res) {
    productRequester.send({type: 'list'}, function(err, products) {
        res.send(products);
    });
});

Perhaps I could see cote returning a handler that accepts req/res to narrow it down to a single line:

app.get('/product', productRequester.httpHandler({type: 'list'}));

But... there are many different frameworks out there. Most of them have express-compatibility so perhaps this may be enough, but could be limiting if you use a library that breaks away from that norm.

dashersw commented 5 years ago

This is route/event based match up. There are multiple other ways possible, including having a single URL and then forwarding to different events based on POST parameters, or configuration when you instantiate a responder:

const responder = new cote.Responder({
  name: 'Products responder', 
  http: {
    server: existingExpressApp, 
    path: '/products/:type'
  }
})
mikield commented 5 years ago

As I already mentioned - I think that should be created as a separated wrapper. Cote is not a Http framework, am I right? @dashersw

Thats why I love to use it. It's not forcing me to follow Http Microframework style, but just to use simple tcp messaging.

Of course I can be wrong.

dashersw commented 5 years ago

You don't have to use any http microframework style — this would just be an addition to how cote operates on its own. A separate wrapper or a plugin can still provide this functionality.