Created
July 16, 2015 03:55
-
-
Save stubailo/a04004c59c8acd4d108a to your computer and use it in GitHub Desktop.
Proxy HTTP API to Meteor publication and method
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
// 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