RouteX is a custom-built API Gateway built from scratch using Go (backend) and React + Vite + TypeScript (frontend). It provides:
- Dynamic Route Mapping (to upstream services)
- JWT & API Key Authentication
- Per-user Rate Limiting (token bucket)
- Admin Panel to manage API Keys, Routes, and Test APIs
- MongoDB Integration for persistence
- Dockerized setup for easy deployment
-
Dynamic Route Mapping → Map
/service-a
→http://upstream-service-a.local
-
Authentication
- Supports JWT (
Authorization: Bearer <token>
) - Supports API Key (
X-API-Key
header)
- Supports JWT (
-
Rate Limiting
- Token bucket per API key/user
- Configurable request rate (
N requests/minute
)
-
MongoDB Integration
api_keys
collection → stores key + rate limitroutes
collection → stores path + upstream target
-
Admin APIs
/admin/api-keys
→ Create/Delete API Keys/admin/routes
→ Create/Delete Routes/admin/generate-token
→ Generate JWT for an API Key
-
Admin Dashboard with pages:
- API Keys: Create & manage API keys & rate limits
- Routes: Create & manage route mappings
- JWT Generator: Generate a JWT for any API Key
- API Tester: Test requests through the Gateway with JWT or API Key
-
Axios API Client: Communicates with backend
-
CORS enabled for dev (
localhost:5173
→localhost:8080
)
-
Admin creates an API Key via admin panel
-
JWT Generator can issue a short-lived JWT for that API Key
-
Clients call Gateway using either:
Authorization: Bearer <jwt>
X-API-Key: <raw-api-key>
Backend validates token → checks MongoDB → enforces rate limit → forwards to upstream service.
Implemented using Token Bucket Algorithm per API Key:
- Each API key has a max tokens (rate limit)
- Tokens refill every minute
- Requests consume 1 token → If no tokens left → 429 Too Many Requests
Method | Path | Description |
---|---|---|
GET | /admin/api-keys |
List API keys |
POST | /admin/api-keys |
Create API key {key, rate_limit} |
DELETE | /admin/api-keys/:id |
Delete API key |
GET | /admin/routes |
List routes |
POST | /admin/routes |
Create route {path, target_url} |
DELETE | /admin/routes/:id |
Delete route |
POST | /admin/generate-token |
Generate JWT for an API Key |
ANY | /your-service-path |
Forwards request to upstream service |
- API Keys Manager: CRUD for API keys
- Routes Manager: CRUD for route mappings
- JWT Generator: Input an API key → Get a signed JWT
- API Tester: Input path, select auth method (JWT/API Key), test request
-
Clone the repository:
git clone https://github.com/Harshvardhan2164/Custom-API-Gateway.git cd Custom-API-Gateway/
-
Start MongoDB, Backend & Frontend
docker compose build docker compose up -d
-
Open Admin Panel →
http://localhost:5173
-
Create an API Key with a rate limit
-
Create Routes mapping
/service
→http://httpbin.org/get
(or any upstream) -
Generate JWT for that API Key
-
Use API Tester → send request with JWT or API Key
-
If you exceed the rate limit → 429 Too Many Requests
- Redis-based distributed rate limiting
- Multi-route custom rate limits
- OAuth2 support
- TLS termination with Nginx
Feel free to fork the repository, open issues, or submit pull requests.
This project is licensed under the MIT License - see the LICENSE file for details.