A RESTful API built with TypeScript
, Node.js
, and SQLite
to track and retrieve GitHub repository statistics such as stars, forks, and open issues.
- Track GitHub repositories by owner and name
- Retrieve statistics (stars, forks, open issues) for each tracked repository
- Update repository stats periodically with
node-cron
- Endpoints for adding, retrieving, and deleting tracked repositories
Node.js
v14 or higher- GitHub Personal Access Token (optional, if you need higher API rate limits)
- Clone the Repository:
git clone https://github.com/aleexcif/github-repository-stats-api.git cd github-repository-stats-api
- Install Dependencies:
npm install
- Set Up Environment Variables:
- Create a .env file to store environment variables (optional).
GITHUB_TOKEN=your_github_personal_access_token`
- Create a .env file to store environment variables (optional).
- Start the Server:
- In development with auto-restart:
npx ts-node-dev --respawn src/app.ts
- In production (compile TypeScript and run
Node.js
):npx tsc node dist/app.js
- In development with auto-restart:
- Add a Repository to Track:
- Method:
POST
- URL:
http://localhost:3000/api/repositories
- curl Command:
curl -X POST http://localhost:3000/api/repositories \ -H "Content-Type: application/json" \ -d '{"owner": "ownerName", "name": "repositoryName"}'
- Example Response:
{ "message": "Repository added successfully", "stats": { "stars": 123, "forks": 45, "openIssues": 10, "lastUpdated": "2024-11-12T08:09:18.417Z" } }
- Method:
- Retrieve All Tracked Repositories:
- Method:
GET
- URL:
http://localhost:3000/api/repositories
- curl Command:
curl -X POST http://localhost:3000/api/repositories
- Example Response:
[ { "id": 1, "name": "repositoryName", "owner": "ownerName", "stars": 123, "forks": 45, "openIssues": 10, "lastUpdated": "2024-11-12T08:09:18.417Z" }, ... ]
- Method:
- Retrieve Stats for a Specific Repository
- Method:
GET
- URL:
http://localhost:3000/api/repositories/{id}
- curl Command:
curl -X GET http://localhost:3000/api/repositories/1
- Example Response:
{ "id": 1, "name": "repositoryName", "owner": "ownerName", "stars": 123, "forks": 45, "openIssues": 10, "lastUpdated": "2024-11-12T08:09:18.417Z" }
- Method:
- Delete a Repository
- Method:
DELETE
- URL:
http://localhost:3000/api/repositories/{id}
- curl Command:
curl -X DELETE http://localhost:3000/api/repositories/1
- Example Response:
{ "message": "Repository deleted successfully" }
- Method:
Note
This should provide a clear overview and easy-to-follow instructions for anyone interested in using this API. Let me know if you’d like me to clarify any sections further!
This project is licensed under the MIT License. See the LICENSE file for details.