Skip to content

Instantly share code, notes, and snippets.

@alexpaul
Created June 12, 2018 14:04
Show Gist options
  • Save alexpaul/4653b46ad6deb1a3b85d7dc607beb4a5 to your computer and use it in GitHub Desktop.
Save alexpaul/4653b46ad6deb1a3b85d7dc607beb4a5 to your computer and use it in GitHub Desktop.
Javascript Fetch API usage to make a GET request for Swift Podcasts
// fetch api making a GET request for Podcasts from Apple Search API
// Asynchronous request so we need to use Promises to listen for completions of task
// filter() is used to get only Swift Podcast related to "Technology" included as part of the genres array
fetch('https://itunes.apple.com/search?media=podcast&limit=200&term=swift')
.then((response) => response.json())
.then((jsonData) => {
const resultCount = jsonData['resultCount']
const results = jsonData['results']
const filteredPodcasts = results.filter((podcast) => (podcast.genres.includes('Technology')))
console.log('total podcast is: ' + results.length)
console.log('filtered podcasts is: ' + filteredPodcasts.length)
console.log(filteredPodcasts[0].collectionName)
filteredPodcasts.forEach((podcast) => console.log(podcast.collectionName + ': ' + podcast.artworkUrl100))
})
.catch((err) => console.error(err))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment