Lightweight API Gateway that routes requests to downstream services, performs token validation and caching using Redis, and exposes public and protected endpoints.
- Run with Docker Compose (from project root):
docker compose up --build- File: src/core/config.py
The gateway reads settings from the GlobalSettings class in src/core/config.py. Defaults can be overridden using a .env file or environment variables.
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.
- File: src/core/config.py
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_URLis configured insrc/core/config.py(defaultredis://redis:6379). The gateway caches token validation results in Redis; ensure a Redis instance is reachable at that URL.
- 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=valCreate the network once on the host if it does not exist:
docker network create null_pointers-net- The gateway routes requests using the
SERVICESmapping. Ensure the service key you add inSERVICESaligns with the routing used by the gateway. - Protected endpoints require a valid
Authorizationtoken. Public endpoints listed inPUBLIC_URLSbypass authentication.