Created
August 19, 2017 09:08
-
-
Save ofanidariyan/0c799bf8a83e00d34ed0169ed149d2f2 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
'use strict'; | |
//Define all dependencies needed | |
const express = require('express'); | |
const responseTime = require('response-time') | |
const axios = require('axios'); | |
//Load Express Framework | |
var app = express(); | |
//Create a middleware that adds a X-Response-Time header to responses. | |
app.use(responseTime()); | |
const getBook = (req, res) => { | |
let isbn = req.query.isbn; | |
let url = `https://www.googleapis.com/books/v1/volumes?q=isbn:${isbn}`; | |
axios.get(url) | |
.then(response => { | |
let book = response.data.items | |
res.send(book); | |
}) | |
.catch(err => { | |
res.send('The book you are looking for is not found !!!'); | |
}); | |
}; | |
app.get('/book', getBook); | |
app.listen(3000, function() { | |
console.log('Your node is running on port 3000 !!!') | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment