Skip to content

Instantly share code, notes, and snippets.

@alexellis
Created September 14, 2015 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alexellis/f3a05cd3e947a77154e9 to your computer and use it in GitHub Desktop.
Save alexellis/f3a05cd3e947a77154e9 to your computer and use it in GitHub Desktop.
Sample in node.js for fetching passage from ESV's restful API in plain-text format
// Author: Alex Ellis 2015
// Sample in node.js for fetching passage from ESV's restful API in plain-text format.
//
// 1) Save this file as esvlookup.js
//
// 2) Install module for making HTTP requests
// npm install request
// 3) Run the program and fetch the passage about being 'born-again'
// node lookup.js John 3:1-3
var request = require('request');
var querystring = require("querystring");
var apikey='TEST';
var lookupKeyWord=function(word) {
var query = {
"passage" : word,
"include-short-copyright" : 0,
"output-format" : "plain-text",
"include-passage-horizontal-lines":"0",
"include-heading-horizontal-lines":"0",
"key" : apikey
}
var requestOptions={
url: 'http://www.esvapi.org/v2/rest/passageQuery?' + querystring.stringify(query),
headers: {
'User-Agent': 'request'
}
};
console.log(requestOptions.url);
request(requestOptions,function(err, response, data) {
console.log(data);
});
}
if( process.argv.length<=2) {
console.log("usage: node esvlookup.js <keyword>");
return 0;
}
if(process.argv.length>=3) {
var keyword=process.argv.slice(2).join(" ").trim();
lookupKeyWord(keyword);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment