Skip to content

Repository files navigation

WrapperGithubApi

WrapperGithubApi is a backend service designed to support the RepEx - GitHub Repositories Explorer project. This API acts as a secure wrapper around GitHub's REST and GraphQL APIs, hiding the GitHub token to prevent exposure on the frontend.

Purpose

This project serves as a secure intermediary layer for GitHub data access in the RepEx project (GitHub Repository Explorer).

Key Features

  • Secure GitHub API access (REST & GraphQL)
  • Built with FastAPI + Uvicorn for high performance
  • Response time logging via middleware
  • Centralized error handler for consistent API responses
  • Centralized configuration using pydantic_settings for cleaner and consistent environment management
  • Rate limiting using SlowAPI to prevent abuse
  • Middleware integrations: CORS, GZip, Trusted Host
  • Secure headers via middleware to prevent Clickjacking, XSS, and insecure redirects
  • Built-in caching using cachetools
  • OpenAPI and ReDoc auto-generated documentation at /docs and /redoc
  • docker-compose.yml to assist local development by provisioning Redis, Redpanda, Redpanda Console, Prometheus, and Grafana services.

Technologies Used

  • Python: The primary programming language.
  • FastAPI: A modern, fast (high-performance) web framework for building APIs with Python.
  • HTTPX: An async HTTP client for making requests to the GitHub API.
  • python-dotenv: A library to load environment variables from a .env file, ensuring that sensitive data (like GitHub tokens) remains secure.
  • Uvicorn: An ASGI server to run the FastAPI application.
  • Cachetools: A caching library used to store frequently requested data to optimize performance and reduce load on the GitHub API.
  • SlowAPI: A FastAPI-compatible rate limiter used to prevent API abuse by restricting the number of requests per client.
  • pydantic_settings: A library for managing application configuration using Pydantic models.
  • redis: A caching solution used to store frequently accessed data externally, helping to improve performance and minimize load on the GitHub API.
  • aiokafka: An asynchronous client library for producing and consuming messages with Kafka.

Installation

  1. Check if Python is installed

    You can verify by running:

    python --version

    If Python is not installed, download and install it from the official website: https://www.python.org/downloads/

  2. Clone the repository

    git clone https://github.com/yourusername/WrapperGithubApi.git
    cd WrapperGithubApi
  3. (Optional) Create a virtual environment

    It’s recommended to use a virtual environment to isolate project dependencies:

    python -m venv venv
    source venv/bin/activate # On Windows: venv\Scripts\activate
  4. Install the required dependencies

    pip install -r requirements.txt
  5. (Optional) If you have Docker installed, you can spin up the services using docker-compose.yml:

    if docker compose version v2

    docker compose up -d

    or

    docker-compose up -d
  6. Set up environment variables

    Create a .env file in the project root directory based on the provided .env.example:

    AUTH_TOKEN=your_github_token# OptionalREDIS_URL=redis://localhost:6379# OptionalKAFKA_SERVER=localhost:19092# OptionalLOGGING_LEVEL=INFO# DEBUG for full logging
  7. Run the application

    Start the FastAPI app using Uvicorn:

    uvicorn app.main:app --reload

    The server will be available at: http://localhost:8000

Available Endpoints

MethodEndpointDescription
GET/reposList repositories
GET/userGet user info
GET/searchSearch GitHub users or repository.
POST/graphqlSubmit GraphQL queries to GitHub's GraphQL API.
Click to expand full list

Repositories

MethodEndpointDescription
GET/repositoriesList public repositories
GET/repos/{user}/{repo}Repo detail
GET/repos/{user}/{repo}/stargazersList repo stragazers
GET/repos/{user}/{repo}/subscribersList repo subscribers
GET/repos/{user}/{repo}/contributorsList repo contributors
GET/repos/{user}/{repo}/branchesList repo branches
GET/repos/{user}/{repo}/activityList repo activity
GET/repos/{user}/{repo}/pullsList repo pulls
GET/repos/{user}/{repo}/issuesList repo issues
GET/repos/{user}/{repo}/languagesList repo languages
GET/repos/{user}/{repo}/topicsList repo topics
GET/repos/{user}/{repo}/readmeRepo readme detail

Users

MethodEndpointDescription
GET/users/{user}Get user info
GET/user/{user}/reposList user repos
GET/user/{user}/followersList user followers
GET/user/{user}/starredList user starred repos
GET/user/{user}/events/publicList user activity

Search

MethodEndpointDescription
GET/search/usersSearch Github user
GET/search/repositoriesSearch repository

GraphQL

MethodEndpointDescription
POST/graphql/queryRequest GitHub's GraphQL API
POST/graphql/searchUserSearch Github user with custom content

Interactive API documentation available at:

  • Swagger UI: /docs
  • ReDoc: /redoc
  • Redpanda console: localhost:8080
  • Prometheus: localhost:9090
  • Grafana: localhost:3000

Usage Example

Once the server is up and running, you can access the available endpoints:

  • Get repository info:

    GET /repos/octocat/Hello-World
  • Get user data:

    GET /user/octocat
  • Query GraphQL:

    POST /graphql/queryContent-Type: application/json
    {
    "query": "{ viewer { login } }"
    }

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any improvements or fixes.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Acknowledgements

This project is part of RepEx - GitHub Repositories Explorer. Check out the main repository for more information.

About

Wrapper for GitHub API to securely access data while hiding the GitHub token from the client/front end, supporting the RepEx - GitHub Repositories Explorer project.

Topics

Resources

Stars

1 star

Watchers

0 watching

Forks

Contributors

Languages