For this assignment, you are going to build a single API endpoint in Express that fetches and caches data from a GitHub API endpoint.
The endpoint you are going to build will be GET
http://localhost:8000/api/github/:username, where :username
can be filled in with a GitHub username (e.g. http://localhost:8000/api/github/iamdtang which is me). When you make a request to this endpoint, use the :username
variable in the URL using request.params
to make a request to https://api.github.com/users/iamdtang (where iamdtang
will be whatever :username
contains) using fetch()
. Write out the entire response from the GitHub API to a file named cache-{username}.json
(e.g. cache-iamdtang.json
) based on the requested username.
Subsequent requests to this endpoint for the same username should read from the cached file instead of making a request to the GitHub API.
When a GitHub API response is successfully cached, use console.log()
to log out GitHub API data was cached for {username} in {file}
. Replace {username}
and {file}
with the actual values.
When reading from the cache, use console.log
to log out GitHub API data for {username} was read from the cache
. Replace {username}
with the actual value.
Code Requirements
- Other than Express, do not reach for any other third-party libraries.
- You can complete this assignment using only
fs.readFile()
,fs.writeFile()
,fetch()
,console.log()
, andJSON.stringify()
- convert JSON into a string of JSON orJSON.parse()
- convert a string of JSON into JSON (depending how it is written). - Don't use
async/await
if you know what that is. - Don't commit
node_modules
. Create a.gitignore
file and addnode_modules
to it.
Submission
Create a video with audio using Zoom where you demo your assignment and explain where you fulfilled or did not fulfill each requirement. Put a link to this recording in the README.md
file at the root of your project.