Skip to content

Instantly share code, notes, and snippets.

@ofanidariyan
Created August 19, 2017 09:08
Show Gist options
  • Save ofanidariyan/0c799bf8a83e00d34ed0169ed149d2f2 to your computer and use it in GitHub Desktop.
Save ofanidariyan/0c799bf8a83e00d34ed0169ed149d2f2 to your computer and use it in GitHub Desktop.
'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