Last active
August 27, 2020 05:23
-
-
Save hellogerard/74762aeeceb69ab5234b to your computer and use it in GitHub Desktop.
Publishing results of a REST API call in Meteor.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Unfortunately, this doesn't work. I wish it did though!