Communicating with External APIs
Lecture Goals
- Explain what an API is
- Explain the limitations of working with an external API
- Observe how to parse API documentation
- Observe how to send a GET request to an external API with / without an API key
Downsides of External APIs

The main upside!

Google Books API Checklist (part 1) - Creating your Project and API key
Google Books API Checklist (part 2) - Adding the API you want to use
- Click the sidebar option for: Enable APIs and Services
- In the search input at the top, type: Books API and select it from the Marketplace search results
- Click the blue enable button to allow your API key to access the Books API
.gitignore
- add a file in the root of your project called
.gitignore
(this should be inside of the 07_ folder)
- this file will contain a list of files & folders for which git will not track changes
- in our case, add
src/keys.js
on its own line within this file.
- ✅⁇: check your version control tab within VSCode and make sure you don’t see your
keys.js
file there. If you do, then check for a mismatch between what you have in your .gitignore
and the name/path to the keys.js
file.
- ✅ When keys.js doesn’t appear in the list of files with untracked changes, you’ve done this step correctly.
Using the API

View docs for more details.
fetch(`https://www.googleapis.com/books/v1/volumes?q=${encodeURI(query)}&key=${API_KEY}`)
.then(res =>res.json())
.then(console.log);