A flexible API rate limiting proxy service that helps manage and control access to third-party APIs.
- API Key Authentication
- Dynamic App Registration
- Configurable Rate Limiting
- Request Queuing
- Proxy Request Forwarding
- Node.js (v14 or higher)
- Redis
- MongoDB
- Clone the repository
- Install dependencies:
npm install
- Copy
.env.example
to.env
and configure your environment variables:
cp .env.example .env
Update the .env
file with your settings:
PORT=3000
REDIS_URL=redis://localhost:6379
MONGODB_URL=mongodb://localhost:27017/rate-limiter
POST /auth/register
Content-Type: application/json
{
"email": "[email protected]",
"password": "your-password"
}
Response:
{
"message": "User registered successfully",
"apiKey": "your-api-key"
}
All app management endpoints require the X-API-Key
header.
POST /apps
Content-Type: application/json
X-API-Key: your-api-key
{
"name": "My API",
"baseUrl": "https://api.example.com",
"rateLimitConfig": {
"strategy": "fixed-window",
"requestCount": 100,
"timeWindow": 60000
}
}
GET /apps
X-API-Key: your-api-key
PUT /apps/:appId
Content-Type: application/json
X-API-Key: your-api-key
{
"rateLimitConfig": {
"requestCount": 200,
"timeWindow": 60000
}
}
DELETE /apps/:appId
X-API-Key: your-api-key
To make requests through the proxy:
[METHOD] /apis/:appId/*
X-API-Key: your-api-key
The proxy will:
- Authenticate your request
- Apply rate limiting
- Forward your request to the registered API
- Return the API response
The service implements a fixed-window rate limiting strategy using Redis. When a request is made:
- The current request count is checked against the configured limit
- If below the limit, the request is forwarded
- If at the limit, the request is queued
- Queued requests are processed when the time window refreshes
# Run in development mode
npm run dev
# Build the project
npm run build
# Run in production mode
npm start
The API uses standard HTTP status codes:
- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 404: Not Found
- 429: Too Many Requests
- 500: Internal Server Error