API Basics - JamesDansie/data-structures-and-algorithms GitHub Wiki
API Basics
Author: James Dansie
API is short for application programming interface. What does that mean? It is the interface that allows us to interact with an application. The cool part is it doesn't need to be our application. By passing a URL in the correct format we will get a response. All of our requests are URLs. For example for IMDB we would use; https://api.themoviedb.org/3/movie/550?api_key=(your key goes here)(your request).
- If your key was (1234)
- and you wanted the movies in theaters (/discover/movie?sort_by=popularity.desc)
- then the url would be; https://api.themoviedb.org/3/movie/550?api_key=1234/discover/movie?sort_by=popularity.desc
The response is typically a JSON with our requested data (so get good at searching through objects). This allows us to build apps that piggy back on other apps. For example our city explorer uses the google maps api, yelp api, and dark sky api, which allows us to use their data without having to build those apps!
The larger services do require us to log in and identify ourselves, but this is typically automated. After we've made an account we can request an API key. This is our personal key that allows us to access their APIs. We need to be careful with these because they can often rack up big bills. These APIs charge per request, if you have an infinite while loop that requests 20,000 times that can add up quickly. This is why we keep these in our .env file, and we don't push that to github.