Skip to content

Instantly share code, notes, and snippets.

@hellogerard
Last active August 27, 2020 05:23
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save hellogerard/74762aeeceb69ab5234b to your computer and use it in GitHub Desktop.
Save hellogerard/74762aeeceb69ab5234b to your computer and use it in GitHub Desktop.
Publishing results of a REST API call in Meteor.
// I need to integrate my company's meteor app with a 3rd party legacy application. Both apps will operate independently, but need to perform CRUD on the legacy datasource. Is there a way to use a REST api built on the legacy system as a datasource in the meteor app?
//Basically I'm looking to do something like the below pseudocode:
Meteor.publish("items", function() {
HTTP.get('https://legacy.app.url/api/items',{ },function(err, items){
return items;
//Or return items.toMeteorCollection()
})
});
// Here's a way to do this.
// Define a local collection on the server (not backed by Mongo) and update the results from the callback to HTTP.get. Something like:
Items = new Meteor.Collection({connection: null});
HTTP.get("http://foo.com", function (err, items) {
_.each(items, function (item) {
Items.insert(item);
});
});
Meteor.publish("items", function () {
return Items.find();
});
@ffxsam
Copy link

ffxsam commented Jul 12, 2015

Unfortunately, this doesn't work. I wish it did though!

@adamgins
Copy link

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment