UNPKG

goodreads-json-api

Version:

Library to get Goodreads API response in JSON format

28 lines (23 loc) 955 B
/** * @desc Demo file showing working of this package. Run node demo.js from demo directory to see json response of API * @author Mukul <@mukul1904> */ 'use strict' const https = require('https'); const goodReadsJSONResponse = require('../index'); const author = 'Neil Gaiman'; const book = 'Neverwhere'; // const API = `https://www.goodreads.com/book/title.xml?author=${author}&key=Uxb0zPb86N4STVy2ECWYA&title=${book}`; const API = 'https://www.goodreads.com/book/title.xml?key=Uxb0zPb86N4STVy2ECWYA&title=harry potter '; // const API = 'https://www.goodreads.com/book/isbn/0441172717?key=Uxb0zPb86N4STVy2ECWYA'; https.get(API, (res) => { res.setEncoding('utf8'); let rawData = ''; res.on('data', (chunk) => rawData += chunk); res.on('end', () => { const response = goodReadsJSONResponse.convertToJson(rawData); console.log(response); }); }).on('error', (e) => { console.log(`Got error: ${e.message}`); });