Best Way to handle a 3rd Party endpoint


#1

I am looking at Restivus for making an API which will encapsulate a 3rd party search endpoint. Is there any method to turn a 3rd party API into a reactive data source, not by necessarily creating a collection for each resource, but is there a way to “publish a collection” by not necessarily storing it? Or is there a way to store it temporarily?

Thanks for all you do.


Sending data from client.js to home.html WITHOUT collections
Push data from server to the client directly
#2

This is relatively straightforward. You set up a client-only collection and a subscription in the usual way.

RestData = new Mongo.Collection('rest-data'); // client only
Meteor.subscribe('rest-docs');

On the server, you poll the REST endpoint at a suitable interval within a roll-your-own publication. Something along the lines of:

Meteor.publish('rest-docs', function() {
  var init = true;
  var self = this;
  Meteor.setInterval(function() {
    var data = HTTP.get('some url').data; // for JSON
    if (init) {
      self.added('rest-data', 'unique_doc_id', {stuff:data});
    } else {
      self.changed('rest-data', 'unique_doc_id', {stuff:data});
    }
    self.ready();
    init = false;
  }, 10000);
});

Also, you could look at any-database, which allows you to connect to a REST endpoint.


Displaying data from external API without MongoDB collection
Broadcast to connected clients
Receiving/Showing realtime data via rpc
Pub-Sub data without mongoDB is not working
Application freezes with reactive vars
Strategy for creating non-persistent server variables for game-player positions?
How to communicate between client and server?
#3

This is completely awesome, thanks sir.


#4

And if I have a method that returns an array that I want to publish? Do I modify it to add each item onto the collection, or do I have to make a Meteor.publish method inside which my method will be called? I don’t quite understand the workflow.


#5

Let me rephrase. Can I add the Meteor.publish inside my Metero.method just before the return of the method, so that I can publish the data to the client?


#6

So, this code you provided works, but why does it need Meteor.setInterval? Why does it not work when I use the native setInterval() provided by Node?