Skip to content

AshOfSpades/gists-api

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Gists API

This project is a FastAPI-based HTTP server that interacts with the GitHub Gists API

This responds to requests on /<USER> with a list of the user’s publicly available Gists. It uses caching for efficiency, logging for observability, and include a test for validation.

Project Structure

├── app
│ ├── __init__.py
│ ├── main.py # FastAPI application entrypoint
│ └── schema.py # Pydantic models for response validation
│
├── tests
│ └── test_main.py # Pytest-based API tests
│
├── Dockerfile # Multi-stage Docker build for production
├── requirements.txt # Python dependencies

Setup & Installation

Running Locally

  1. Clone the repository

    git clone https://github.com/EqualExperts-Assignments/equal-experts-fortunate-astonishing-impeccable-professor-857ba32a0786.git
    cd equal-experts-fortunate-astonishing-impeccable-professor-857ba32a0786
    
  2. Create a virtual environment (optional but recommended)

    python3 -m venv venv
    source venv/bin/activate
    
  3. Install dependencies

    pip install -r requirements.txt
    
  4. Run the server

     uvicorn app.main:app --reload
    

Optionally you can add --port <potr_number> if you want server to run on a specific port

Running with Docker

  1. Go in the directory where Dockerfile is present and run the following command to build the Docker image

    docker build -t gists-api .
    
  2. Run the container

    docker run -p 8080:8080 gists-api
    

API will be available at:
http://localhost:8080

API Usage

Endpoint

GET /{user}?per_page={int}&page={int}

  • user: GitHub username (required)

  • per_page: Number of gists per page (default: 10)

  • page: Page number (default: 1)

Example curl http://127.0.0.1:8000/octocat?per_page=5&page=1

Response (shortened example)
[
  {
    "id": "6cad326836d38bd3a7ae",
    "url": "https://api.github.com/gists/6cad326836d38bd3a7ae",
    "...": "other fields allowed"
  }
]

Running Tests

To run tests locally:

pytest

Notes

  • The schema only validates id and url, while allowing extra fields to remain flexible against GitHub API changes.

  • Results are cached for 5 minutes to avoid repeated GitHub API calls.

  • Error handling:

    • 404: User not found

    • 500: Internal server error

About

assignment for EE

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published