Skip to content

Instantly share code, notes, and snippets.

@kerminz
Created May 13, 2019 12:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kerminz/7eab6720ef20bb6db45b1482aa471494 to your computer and use it in GitHub Desktop.
Save kerminz/7eab6720ef20bb6db45b1482aa471494 to your computer and use it in GitHub Desktop.
Basic REST API with NodeJS and Express
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