mirror of
https://github.com/furyhawk/api_gateway.git
synced 2026-07-21 02:06:50 +00:00
1528a7c7697dfd21e9061fbd830f3c8e4b262730
- Create core application structure with FastAPI - Implement dynamic route registration and management endpoints - Define configuration models for gateway settings, upstreams, and routes - Add proxy request handling for upstream services - Include example configuration and OpenAPI specification files - Set up development dependencies and project metadata
OpenAPI API Gateway Framework
This repository now includes a lightweight, configurable API gateway framework built with FastAPI.
What It Provides
- Dynamic gateway routes loaded from YAML (
config/gateway.yaml) - Configurable upstream targets and per-upstream timeout settings
- OpenAPI docs for gateway endpoints via FastAPI (
/docs) - Optional serving of an external OpenAPI contract (
/openapi/external.json) - Built-in management endpoints:
GET /healthzGET /readyzGET /admin/routes
Project Structure
src/gateway_framework/app.py: app factory and dynamic route registrationsrc/gateway_framework/proxy.py: request forwarding/proxy logicsrc/gateway_framework/config.py: config schema and loadersrc/gateway_framework/main.py: ASGI entrypointconfig/gateway.yaml: route and upstream configurationopenapi_json/lta_datamall_openapi_v0-1-1.json: external OpenAPI contract
Quick Start
- Create and activate a virtual environment.
- Install dependencies:
pip install -e .
- Update
config/gateway.yamlwith real upstream URLs. - Run the gateway:
uvicorn gateway_framework.main:app --reload --app-dir src
- Open the docs:
http://127.0.0.1:8000/docs
Configuration Model
config/gateway.yaml uses this model:
settings:
title: string
version: string
description: string
external_openapi_file: path/to/openapi.json
upstreams:
service_name:
base_url: https://service.example.com/
timeout_seconds: 15
routes:
- path: /api/v1/resource
methods: [GET, POST]
upstream: service_name
upstream_path: /v2/resource
strip_prefix: /api
summary: Optional operation summary
tags: [Gateway]
operation_id: gateway_resource_get
Notes:
pathis the public gateway path.upstream_pathoverrides forwarded path.strip_prefixremoves a leading path segment before forwarding.
Scaling and Configurability Guidance
- Add routes through config, not code, for repeatable deployments.
- Split large configurations into environment-specific files and set
GATEWAY_CONFIG_PATH. - Keep route changes backward compatible (
/api/v1stability) for client safety. - Define explicit timeout values per upstream to isolate slow dependencies.
Next Steps
- Add auth/rate limiting middleware for production.
- Add OpenAPI linting in CI (for example, Redocly CLI).
- Add contract tests for every configured route.
Languages
Python
76.2%
JavaScript
8.2%
CSS
6%
Makefile
4.7%
HTML
4.4%
Other
0.5%