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 /api/github/:username
, where :username
can be filled in with a GitHub username (e.g. /api/github/iamdtang
). When you make a request to this endpoint, use the :username
variable in the URL to make a request to https://api.github.com/users/iamdtang (where iamdtang
will be whatever :username
contains) using Axios. Extract out the public_repos
property in the response and write it out to a file named after the requested username (e.g. iamdtang.txt). Your endpoint should respond with JSON structured as follows, where reposCount
contains the value from public_repos
:
{
"repoCount": 121
}
Subsequent requests to this endpoint for the same username should read the repo count from the file instead of making a request to the GitHub API and should still respond with the response above.
Code Requirements
- When using the fs module, only use the writeFile() and readFile() methods.
- To make the request using Axios, use
axios.get()
.
Submission
Create a short video using Zoom where you demo your endpoint. Please use 2 different GitHub usernames in your video demo. Create a brand new repository for this assignment. Send an email to Brighton and me with the URL to your GitHub repository and the link to your Zoom video with the subject: "ITP 405 - Assignment 10".