Aldee
Aldee

Reputation: 4518

StrongLoop Websockets

I need a real-time data to be streamed by a client app. Does StrongLoop (or any StrongLoop component) supports websockets-based CRUD. Consider this image:

enter image description here

Please advise.

Upvotes: 2

Views: 249

Answers (1)

danielrvt
danielrvt

Reputation: 10916

I'm not sure if I understand correctly, but in my opinion it's totally doable. In your image, there is an intermediate layer between your client app and your API. Assuming such layer exists, it should call your API's endpoints whenever a given event is emitted in your client app.

I would suggest using http://socket.io/ and plain old http://expressjs.com/ with http://visionmedia.github.io/superagent/ for you intermediate layer.

Something like this:

var app = require('http').createServer(handler)
var io = require('socket.io')(app);
var request = require('superagent');

app.listen(80);

io.on('connection', function (socket) {
  socket.on('eventOne', function (data) {
      request
      .get('/yourapiurl/someresource')
      .end(function(err, res){
          socket.emit('get-someresource', res.body);
      });
  });
});

I wouldn't suggest using websockets in the same Strongloop project because, I don't know how complex your API is. This may increase your API complexity and lower your API maintainability.

BTW. You didn't mention what type of data you are trying to send via websockets.

Upvotes: 1

Related Questions