Last active
October 10, 2019 06:23
-
-
Save jmagrippis/0b1eabd68eaa659aaa0f92b2358cdc31 to your computer and use it in GitHub Desktop.
A resolver to fetch all the breeds from the Dog API (returns list)
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 fetch = require('node-fetch') | |
const breeds = () => | |
fetch('https://dog.ceo/api/breeds/list/all') | |
.then((response) => response.json()) | |
.then(({ message }) => | |
Object.entries(message).reduce((acc, [breed, subbreeds]) => { | |
if (subbreeds.length) { | |
for (const subbreed of subbreeds) { | |
acc.push(`${breed} ${subbreed}`) | |
} | |
} else { | |
acc.push(breed) | |
} | |
return acc | |
}, []) | |
) | |
module.exports = breeds |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment