Created
May 13, 2019 12:26
-
-
Save kerminz/7eab6720ef20bb6db45b1482aa471494 to your computer and use it in GitHub Desktop.
Basic REST API with NodeJS and Express
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
const request = require('request') | |
const express = require('express') | |
const app = express() | |
app.get('/', (req, res) => { | |
if (!req.query.search) { | |
return res.send('Please provide a search string...') | |
} | |
const url = 'http://api.giphy.com/v1/gifs/search?q=' + encodeURIComponent(req.query.search) + '&api_key=YOUR_API_KEY' | |
request( { url, json: true }, (error, {body}) => { | |
if (error) { | |
return res.send('Unable to connect.') | |
} | |
res.send(body) | |
}) | |
}) | |
app.listen(3000, () => { | |
console.log('Server is up!') | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment