A simple reverse proxy API gateway for routing requests to multiple backend services from a single endpoint.
- Single entry point for multiple backend services
- Hot reloading with Air during development
- Request logging
- Health check endpoint
- Dynamic service configuration via YAML
- Language-agnostic: works with any HTTP backend service (Go, Node.js, Python, Ruby, Java, .NET, etc.)
flowchart TD
subgraph Mobile App
Client[Mobile App]
end
subgraph API Gateway
Gateway[API Gateway<br/>:8080]
HealthCheck("Health Check<br/>(/health)")
Router[Request Router]
end
subgraph Backend Services
Service1[Service 1<br/>localhost:3001]
Service2[Service 2<br/>localhost:3002]
end
Client -->|HTTP Requests :8080| Gateway
Gateway -->|/health| HealthCheck
Gateway --> Router
Router -->|/api/service1/*| Service1
Router -->|/api/service2/*| Service2
style Gateway fill:#4a90d9,stroke:#2c5282,stroke-width:2px
style Service1 fill:#48bb78,stroke:#2f855a,stroke-width:2px
style Service2 fill:#48bb78,stroke:#2f855a,stroke-width:2px
style Client fill:#ed8936,stroke:#c05621,stroke-width:2px
sequenceDiagram
participant Client as Mobile App
participant Gateway as API Gateway
participant S1 as Service 1 (:3001)
participant S2 as Service 2 (:3002)
Client->>Gateway: GET /api/service1/users
Gateway->>S1: Forward request
S1-->>Gateway: Response
Gateway-->>Client: Return response
Client->>Gateway: POST /api/service2/orders
Gateway->>S2: Forward request
S2-->>Gateway: Response
Gateway-->>Client: Return response
Note over Client,Gateway: Health Check
Client->>Gateway: GET /health
Gateway-->>Client: OK
api-gateway/
├── .air.toml # Air configuration for hot reloading
├── config/
│ ├── config.go # Configuration loader
│ └── config.yaml # Default configuration
├── go.mod # Go module file
├── main.go # Main gateway application
├── README.md # This file
└── tmp/ # Auto-generated by Air (gitignored)
To add a new service, simply add it to config/config.yaml:
services:
- name: go-service
path: /api/go-service/
url: http://localhost:3001
- name: nodejs-service
path: /api/nodejs/
url: http://localhost:3002
- name: python-service
path: /api/python/
url: http://localhost:3003The gateway is language-agnostic - it forwards HTTP requests to any backend service regardless of the language or framework used. Add services written in Go, Node.js, Python, Ruby, Java, .NET, or any other technology that exposes an HTTP endpoint.
No code changes required. Air will automatically reload the gateway with the new configuration.
All incoming requests and responses are logged to the console with the following information:
- Client IP - IP address and port of the requesting client
- Request method and path - e.g.,
GET /api/service1/users - Target backend - which service the request is proxied to
- Response status code - HTTP status returned by the backend
- Response duration - time taken to process the request
[10.0.2.2:52341] Incoming request: GET /api/service1/users
[10.0.2.2:52341] Proxying to service1: GET /api/service1/users
[10.0.2.2:52341] GET /api/service1/users - 200 - 1.245ms
This helps you monitor traffic and diagnose issues during development.
For Android Emulator, use the special IP address to access the host machine:
http://10.0.2.2:8080
The Android emulator uses 10.0.2.2 as a special alias to your host machine's loopback interface (equivalent to 127.0.0.1).
For physical devices or other emulators, use your machine's IP address:
http://YOUR_IP:8080
Where YOUR_IP is your local machine's IP address (e.g., 192.168.1.100).
To find your IP:
- Linux/Mac:
ifconfigorip addr - Windows:
ipconfig
- Ensure your backend services are running on the specified ports
- Check that services are listening on
localhostor0.0.0.0
- For Android Emulator, use
http://10.0.2.2:8080instead oflocalhost - For physical devices, verify your machine's IP address
- Ensure the gateway is listening on
0.0.0.0:8080(not justlocalhost) - Check firewall settings allow connections on port 8080
go install github.com/air-verse/air@latest
export PATH=$PATH:$(go env GOPATH)/binSee LICENSE for details.
