Skip to content

GU-null-pointers/API-Gateway

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

API Gateway

Lightweight API Gateway that routes requests to downstream services, performs token validation and caching using Redis, and exposes public and protected endpoints.

Quick Start

  • Run with Docker Compose (from project root):
docker compose up --build

Configuration

The gateway reads settings from the GlobalSettings class in src/core/config.py. Defaults can be overridden using a .env file or environment variables.

Adding a service

Downstream services are declared in the SERVICES mapping. Add an entry mapping a short service name to its base URL. Example:

# in src/core/config.py
GOODS_SERVICE_URL = "http://goods_service:8000"
SERVICES = {
    "auth": AUTH_SERVICE_URL,
    "goods": GOODS_SERVICE_URL,
}

Use the service key (for example goods) when routing requests to that downstream service.

Public URLs (no authentication)

The PUBLIC_URLS list contains paths that bypass authentication (no Authorization header required). Defaults include /health, /auth/login, /auth/register, and /auth/refresh.

To add a public endpoint, append the path to PUBLIC_URLS, for example:

Redis / Caching

  • REDIS_URL is configured in src/core/config.py (default redis://redis:6379). The gateway caches token validation results in Redis; ensure a Redis instance is reachable at that URL.

Docker Compose networking requirement

  • The gateway and downstream services (and Redis when containerized) must be on the same Docker network used by this compose setup.
  • Network name used by this project: null_pointers-net.

If you run your own services in a separate docker-compose.yml, attach them to the same external network. Example snippet to include in your compose file:

networks:
  null_pointers-net:
    external: true

services:
  goods_service:
    image: myorg/goods:latest
    networks:
      - null_pointers-net
    environment:
      - SOME_VAR=val

Create the network once on the host if it does not exist:

docker network create null_pointers-net

Routing / Usage notes

  • The gateway routes requests using the SERVICES mapping. Ensure the service key you add in SERVICES aligns with the routing used by the gateway.
  • Protected endpoints require a valid Authorization token. Public endpoints listed in PUBLIC_URLS bypass authentication.

About

API Gateway implementation with FastAPI

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors