Objective: Make a music search app using jQuery, AJAX, and the Spotify API. You'll be using Spotify's search endpoint to search for tracks (songs).
- Your app must have a form to search for tracks (songs). The form needs an input field for the search keyword.
- When a user submits the form, use jQuery to get the search keyword from the form input.
- Use AJAX to call Spotify's search endpoint with the search keyword from the form.
- On success of the AJAX call, render the search results on the page. You should include at least the track name and artist name.
- Each time the user submits the form, clear the previous search results from the view.
- Display a track's album artwork next to each search result in the view. Hint: You'll notice if you try to access the album artwork but none is available, your app will break. Prevent this from happening with a check to see if any artwork is available first.
- Spotify gives us a
preview_url
for each track. Create a play button for each track in your view that opens thepreview_url
in a new tab (it will start playing the song!). - It would be nice to let the user know something is happening in the few milliseconds between submitting the form and getting data on the page. Show
loading.gif
when the form submits, and hide it when you get data back from Spotify. - Handle the case where no data comes back from Spotify. You'll want to let the user know that there are no results, rather than just showing a blank page.
- Fork this repo, and clone it into your
devel
folder on your local machine. - Practice querying Spotify's search endpoint using Postman with a couple different search keywords. You'll want to set
type=track
in your request URL. Look at the response data, and figure out how you would access the track name and artist name for a particular track (this will involve accessing values from nested objects and arrays). - Once you feel comfortable with the structure of the response data, work on using AJAX to make the API call to Spotify when the user submits the form.
- Start by
console.log
-ing the response data. Once you have that working, access the data you need (track name and artist name), and use jQuery toappend
it to the page. Hint: You'll need to use Array#forEach to iterate through all the tracks Spotify returns in the response data.
- As you make code changes, frequently commit and push to GitHub.
- Once you've finished the assignment and pushed your work to GitHub, make a pull request from your fork to the original repo.
- Note the pull-request will not be merged, as all other students' work would then conflict.