cote icon indicating copy to clipboard operation
cote copied to clipboard

Is there something of http gateway?

Open zhaoyao91 opened this issue 7 years ago • 8 comments

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?

zhaoyao91 avatar Nov 14 '18 13:11 zhaoyao91

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.

dashersw avatar Nov 14 '18 13:11 dashersw

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.

mikield avatar Jan 20 '19 23:01 mikield

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.

mistresseve666 avatar Jun 29 '19 03:06 mistresseve666

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.

dashersw avatar Jun 30 '19 00:06 dashersw

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.

mistresseve666 avatar Jun 30 '19 00:06 mistresseve666

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'
  }
})

dashersw avatar Jul 03 '19 07:07 dashersw

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.

mikield avatar Jul 03 '19 14:07 mikield

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.

dashersw avatar Jul 03 '19 21:07 dashersw