Skip to content

Instantly share code, notes, and snippets.

@stubailo
Created July 16, 2015 03:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save stubailo/a04004c59c8acd4d108a to your computer and use it in GitHub Desktop.
Save stubailo/a04004c59c8acd4d108a to your computer and use it in GitHub Desktop.
Proxy HTTP API to Meteor publication and method
// code not guaranteed to work!!!! never ran it
// On the server
Meteor.publish("myData", {
var subscription = this;
var data = HTTP.call("https://reddit.com/r/funny.json").data.children;
data.forEach(function (item) {
subscription.added("my-collection", item);
});
});
Meteor.method({
postToApi: function (argument) {
HTTP.post("url", {
data: argument
});
}
})
// On the client
var C = new Mongo.Collection("my-collection");
var handle = Meteor.subscribe("myData");
C.find(...)
handle.stop();
Template.widgets.onCreated(function () {
this.subscribe("myData");
});
Template.widgets.events({
"click button": function () {
Meteor.call("postToApi", "stuff");
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment