DGate v2 - Rust Edition
A high-performance API Gateway written in Rust, featuring JavaScript module support via QuickJS engine.
Features
- High Performance: Built with Rust and async I/O using Tokio
- Dynamic Routing: Configure routes, services, and domains dynamically via Admin API
- Namespace Isolation: Organize resources into namespaces for multi-tenancy
- Simple KV Storage: Document storage without JSON schema requirements
- TLS Support: HTTPS with dynamic certificate loading per domain
- Reverse Proxy: Forward requests to upstream services with load balancing support
Supported
- HTTP/1.1 ✅
- HTTP/2 ✅
- WebSocket ✅
- gRPC ✅
- QUIC/HTTP3 ❌
Resource Diagram
┌─────────────────────────────────────────────────────────────┐
│ DGate V2 │
├─────────────────────────────────────────────────────────────┤
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Domains │───▶│ Namespaces │───▶│ Routes │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │
│ ▼ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Modules │◀───│ Handler │───▶│ Services │ │
│ │ (QuickJS) │ └─────────────┘ │ (Upstream) │ │
│ └─────────────┘ └─────────────┘ │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Documents │ │ Secrets │ │ Collections │ │
│ │ (KV) │ └─────────────┘ └─────────────┘ │
│ └─────────────┘ │
│ │
└─────────────────────────────────────────────────────────────┘
Installation
From Cargo (crates.io)
From Source
Docker
# Pull from GitHub Container Registry
# Run with a config file
Quick Start
Run
# With default config
# With custom config
Configuration
Create a config.dgate.yaml file:
version: v1
log_level: info
storage:
type: file
dir: .dgate/data/
proxy:
port: 80
host: 0.0.0.0
admin:
port: 9080
host: 0.0.0.0
Resources
Namespaces
Namespaces organize resources and provide multi-tenancy:
# Create a namespace
Services
Services define upstream endpoints:
Routes
Routes match incoming requests to services:
Modules
JavaScript modules for request/response processing:
# Create a module
Module Functions:
// Modify request before proxying
// Handle request without upstream (serverless-style)
// Modify response after upstream
// Handle errors
// Custom upstream URL selection
Domains
Control ingress traffic routing:
Collections & Documents
Simple KV storage:
# Create a collection
# Create a document
# Get document
Secrets
Store sensitive data:
API Reference
Admin Endpoints
| Method | Path | Description |
|---|---|---|
| GET | / |
Root info |
| GET | /health |
Health check |
| GET | /readyz |
Readiness check |
| GET | /api/v1/namespace |
List namespaces |
| PUT | /api/v1/namespace/:name |
Create/update namespace |
| DELETE | /api/v1/namespace/:name |
Delete namespace |
| GET | /api/v1/route |
List routes |
| PUT | /api/v1/route/:ns/:name |
Create/update route |
| DELETE | /api/v1/route/:ns/:name |
Delete route |
| GET | /api/v1/service |
List services |
| PUT | /api/v1/service/:ns/:name |
Create/update service |
| DELETE | /api/v1/service/:ns/:name |
Delete service |
| GET | /api/v1/module |
List modules |
| PUT | /api/v1/module/:ns/:name |
Create/update module |
| DELETE | /api/v1/module/:ns/:name |
Delete module |
| GET | /api/v1/domain |
List domains |
| PUT | /api/v1/domain/:ns/:name |
Create/update domain |
| DELETE | /api/v1/domain/:ns/:name |
Delete domain |
| GET | /api/v1/collection |
List collections |
| PUT | /api/v1/collection/:ns/:name |
Create/update collection |
| DELETE | /api/v1/collection/:ns/:name |
Delete collection |
| GET | /api/v1/document?namespace=x&collection=y |
List documents |
| PUT | /api/v1/document/:ns/:col/:id |
Create/update document |
| DELETE | /api/v1/document/:ns/:col/:id |
Delete document |
| GET | /api/v1/secret |
List secrets |
| PUT | /api/v1/secret/:ns/:name |
Create/update secret |
| DELETE | /api/v1/secret/:ns/:name |
Delete secret |
| GET | /api/v1/changelog |
List change logs |
Environment Variables
| Variable | Description | Default |
|---|---|---|
LOG_LEVEL |
Logging level | info |
PORT |
Proxy server port | 80 |
PORT_SSL |
HTTPS port | 443 |
DG_DISABLE_BANNER |
Disable startup banner | - |
Performance
DGate v2 is built for high performance:
- Async I/O: Non-blocking operations with Tokio
- Zero-copy: Efficient buffer handling
- Connection Pooling: Reuse upstream connections
- Module Caching: Compiled JS modules are cached
Comparison with v1 (Go)
| Feature | v1 (Go) | v2 (Rust) |
|---|---|---|
| Runtime | Go 1.21+ | Rust 1.75+ |
| JS Engine | goja | QuickJS (rquickjs) |
| HTTP | chi/stdlib | axum/hyper |
| Storage | badger/file | redb/memory |
| Documents | JSON Schema | Simple KV |
Development
Running Tests
# Unit tests
# Functional tests
# Performance tests (requires k6)
Building for Release
License
MIT License