Skip to content

Instantly share code, notes, and snippets.

@jmagrippis
Last active October 10, 2019 06:23
Show Gist options
  • Save jmagrippis/0b1eabd68eaa659aaa0f92b2358cdc31 to your computer and use it in GitHub Desktop.
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)
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