Skip to content

Instantly share code, notes, and snippets.

@dimorphic
Created September 28, 2018 08:30
Show Gist options
  • Select an option

  • Save dimorphic/ffac5cc79cc6521451496df3182a2097 to your computer and use it in GitHub Desktop.

Select an option

Save dimorphic/ffac5cc79cc6521451496df3182a2097 to your computer and use it in GitHub Desktop.
Giphy.com API fetch
// https://github.com/dimorphic/bitch.pizza/blob/master/src/js/get-giphy.js
// Get your key @ https://developers.giphy.com/
const GIPHY_API_KEY = '<KEY-HERE>'; // random key. Get your own!
// Giphy API defaults
const API = {
baseURL: 'https://api.giphy.com/v1/',
resource: 'gifs',
key: GIPHY_API_KEY,
tag: 'pizza',
type: 'random',
rating: 'R' // ?
};
// https://api.giphy.com/v1/gifs/random?api_key=<:KEY>&tag=pizza&rating=G
const giphyEndpoint = encodeURI(
`${API.baseURL}${API.resource}/${API.type}`
+ `?api_key=${API.key}`
+ `&tag=${API.tag}`
+ `&rating=${API.rating}`
);
export default () => {
console.log('๐Ÿ• #ftw / thx Giphy ๐Ÿ’–');
return fetch(giphyEndpoint)
.then(res => res.json())
.then(json => json.data)
.catch(err => new Error(err));
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment