Created
September 14, 2015 15:49
-
-
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
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
// 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