Created
September 28, 2018 08:30
-
-
Save dimorphic/ffac5cc79cc6521451496df3182a2097 to your computer and use it in GitHub Desktop.
Giphy.com API fetch
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
| // 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