Skip to content

Instantly share code, notes, and snippets.

@noahbass
Last active July 26, 2016 13:10
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noahbass/848963ef1c21fb8d0e00 to your computer and use it in GitHub Desktop.
Save noahbass/848963ef1c21fb8d0e00 to your computer and use it in GitHub Desktop.
Meteor external api example: bibles.org api
<head>
<title>meteor external api example</title>
</head>
<body>
<table>
<p>{{{verse.verse}}}</p>
<p>{{{verse.text}}}</p>
</table>
</body>
if (Meteor.isClient) {
Verse = new Mongo.Collection('verse');
Meteor.subscribe('getVerse');
Template.body.helpers({
verse: function() {
return Verse.findOne();
}
});
}
if (Meteor.isServer) {
Meteor.publish('getVerse', function() {
var self = this;
try {
var res = HTTP.get('https://bibles.org/v2/chapters/eng-KJVA:1Cor.2/verses.js', {
auth: 'bibles.orgapikey:'
});
var item = JSON.parse(res.content);
var item = item.response;
var doc = {
text: item.verses[0].text,
verse: item.verses[0].verse
};
self.added('verse', Random.id(), doc);
self.ready();
} catch(error) {
console.log(error);
}
});
}
# Meteor packages used by this project, one per line.
#
# 'meteor add' and 'meteor remove' will edit this file for you,
# but you can also edit it by hand.
meteor-platform
insecure
http
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment