kuzzleio / sdk-javascript

Kuzzle Javascript SDK. High level library including multi-protocol support, offline resiliency, realtime data and more
http://docs.kuzzle.io/sdk/js/7
Apache License 2.0
39 stars 15 forks source link

Provide an option to use the HTTP protocol instead of the WebSocket one in the SDK #167

Closed PierreCavalet closed 6 years ago

PierreCavalet commented 7 years ago

Are you going to add an option to use the HTTP protocol in the SDK ? It is currently using the websocket protocol and we don't need to maintain the connection between kuzzle and our client.

It seems that there is some limitations in terms of performance (WS vs HTTP).

We are currently using the REST API with Axios (HTTP client library) and we think it's best to use the SDK if you are going to develop this feature soon. We are waiting for this information to decide if we use the REST API with Axios or the javascript SDK.

ballinette commented 7 years ago

Hi. Yes, we plan to do that. A proposition from @xbill82 for that : we add a parameter protocol to SDK constructor to say if we want to user "http" or "websocket" protocol.

If we want to use both of them depending the method, we can instantiate 2 SDK objects, one for each protocol, like that:

var
  httpKuzzle = new Kuzzle('kuzzle.host', {protocol: 'http'}),
  wsKuzzle = new Kuzzle('kuzzle.host', {protocol: 'websocket'});

// (...)

// Search, using HTTP : 
var filter = {filter: {...}};
httpKuzzle
  .dataCollectionFactory('collection', 'index')
  .search(filter, function (err, res) {
    res.documents.forEach(document => {
      console.log(document.toString());
    });
  });

// (...)

// Subscribe, using websocket : 
wsKuzzle
  .dataCollectionFactory('collection', 'index')
  .subscribe({equals: {title: 'foo'}}, function (err, res) {
    res.documents.forEach(document => {
      console.log(document.toString());
    });
  });

To simplify the implementation of this, we need to wait the implementation of following improvement on Kuzzle Proxy: https://github.com/kuzzleio/kuzzle-proxy/issues/40

PierreCavalet commented 7 years ago

It seems fine to me.

I think it's better to deal with a constructor parameter protocol than having to write it in every request even if it means that we have to instantiate multiple SDK objects when we want to use multiple protocols.

I suppose you are going to make websocket as a default value for backwards compatibility.

We are going to use Axios and the REST API for now and depending on how much time it will take to develop this feature, we will switch to the Javascript SDK.

xbill82 commented 7 years ago

@PierreCavalet the only "tricky" thing about the multiple SDK instances scenario is when it comes to the authentication token, which is actually the only state that the Kuzzle instance has to care about. This state must be kept in sync between both instances, which is not really a burden when it's only one attribute value.

We didn't find any more tricky parts but if you find any, please give feedback!