This project is a simple JSON-based API built with Laravel that allows users to manage their GitHub starred repositories by adding tags for better categorization and searching.
- Fetch Starred Repositories: Retrieve a GitHub user's starred repositories.
- Add Tags: Add custom tags to starred repositories for better organization.
- Search Repositories: Search starred repositories by tags.
- RESTful API: Built with REST principles, providing a clean and consistent interface.
- Unit Testing: Includes unit tests to ensure reliability.
To run this project, you need the following installed:
- PHP (>=8.1)
- Composer
- MySQL
- Laravel (>=10.x)
- Git
- A GitHub Personal Access Token (for API requests)
Follow these steps to set up the project locally:
git clone https://github.com/your-username/github-tags-api.git
cd github-tags-api
composer install
Copy the .env.example
file to .env
:
cp .env.example .env
Edit .env
to configure your database:
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=github_tags_api
DB_USERNAME=root
DB_PASSWORD=yourpassword
Add your GitHub Personal Access Token (for API requests):
GITHUB_TOKEN=your_github_personal_access_token
Create the database and run the migrations:
php artisan migrate
php artisan serve
The API will be available at http://127.0.0.1:8000
.
POST /api/repositories/sync
Fetches and syncs starred repositories for a given GitHub username.
Request Body:
{
"username": "octocat"
}
Response:
{
"message": "Repositories synced successfully"
}
POST /api/repositories/{repositoryId}/tags
Adds a tag to a repository.
Request Body:
{
"name": "javascript"
}
Response:
{
"message": "Tag added successfully"
}
DELETE /api/repositories/{repositoryId}/tags/{tagId}
Removes a tag from a repository.
Response:
{
"message": "Tag removed successfully"
}
GET /api/repositories/search?tag=javascript
Searches for repositories tagged with a specific keyword.
Response:
[
{
"id": 1,
"github_id": 123456,
"name": "react",
"description": "A library for building UI",
"url": "https://github.com/facebook/react",
"language": "JavaScript"
}
]
Run the test suite using:
php artisan test
Example test output:
PASS Tests\Feature\RepositoryTest
✓ Fetch starred repositories
✓ Add tag to a repository
✓ Search repositories by tag
- Configure a cloud Linux server with PHP, MySQL, Composer, and a web server (Nginx/Apache).
- Clone this repository onto the server.
- Set up environment variables in
.env
. - Configure your web server to point to the Laravel
public
directory. - Run migrations and start the application.
- Laravel Framework
- MySQL Database
- GitHub REST API
- PHPUnit for Testing
- Add authentication for API requests.
- Implement pagination for repositories.
- Cache GitHub API responses to reduce API calls.
- Deploy using Docker for easier scalability.
This project is licensed under the MIT License.