Routing and Upstream
Routing Concept
Routing consists of two fundamental components in an API Proxy:
The entry point where requests enter the API Proxy. Clients send requests to this endpoint.
The backend API where requests are routed. The API Proxy sends requests to this address.
Routing Flow
The following diagram shows how request and response flow occurs through the Gateway with the Routing and Upstream mechanism:
Client sends request to API Proxy
Entry point where requests enter the API Proxy
Path, Method, Protocol and Port definitions
Load Balancing, Failover and routing logic is applied
Backend API where requests are routed
Backend address, protocol and configuration
Processed request is sent to backend API
Upstream Target
Upstream Target is the address of the backend API to which requests from clients in an API Proxy are routed. Upstream Target is the point where the API Proxy communicates with the backend.
Upstream Target Overview
Upstream and target concepts are fundamental concepts used when routing to backend services in API Proxies. Upstream Target represents the physical or logical address of the backend API. The API Proxy routes requests coming from Client Route to this target.
URL or IP address of the Backend API
HTTP, HTTPS, gRPC, WebSocket protocols
Load balancing between multiple backend instances
Switching to alternative backend in error conditions
Upstream and Target
Upstream: Configuration where backend services to which the API Proxy routes requests are defined. An upstream can contain multiple targets.
Target: Backend service addresses defined within an upstream. Each target contains a URL and necessary configuration information.
Upstream Target Structure
An Upstream Target contains the following information:
http://backend-service:8080/api/products
│ │ │ │
│ │ │ └─ Backend Path
│ │ └─ Port
│ └─ Host/Service Name
└─ Protocol
Example Upstream Targets
http://product-service:8080
https://api.backend.com/v1
grpc://backend-service:50051
ws://websocket-service:8080
Upstream Target Configuration
When creating an Upstream Target, the following information is defined:
Basic Configuration
- URL: Address of the Backend API
- Protocol: HTTP, HTTPS, gRPC, WebSocket
- Host: Backend server name or IP
- Port: Backend port number
- Path: Backend path (optional)
- Path Rewrite: Changing backend path (optional)
Path Rewrite
Path rewrite can be performed in Upstream Target:
Client Route: /api/v1/products
│
▼ (Path Rewrite)
Upstream Target: /products
│
▼
Backend API: http://backend:8080/products
Path Rewrite Examples:
/api/v1/products→/products(prefix removal)/api/v1/products→/v2/products(version change)/api/products/{id}→/products/{id}(path simplification)
Timeout Settings
- Connection Timeout: Connection timeout
- Read Timeout: Read timeout
- Write Timeout: Write timeout
Upstream Target Types
Single backend instance:
http://backend:8080
Multiple backend instances (Load Balanced):
http://backend1:8080
http://backend2:8080
http://backend3:8080
Backend determined dynamically:
Variable-based target selection
Routing Types
The Apinizer platform provides routing support for different protocols:
Routing for HTTP/HTTPS protocol. Used for REST APIs.
Routing for gRPC protocol. Used for microservice architectures.
Routing for WebSocket protocol. Used for real-time communication.
HTTP Routing
HTTP Routing is routing support for REST APIs using HTTP/HTTPS protocol.
HTTP Routing Features
- HTTP/1.1
- HTTP/2
- HTTPS (TLS/SSL)
- GET, POST, PUT, DELETE
- PATCH, HEAD, OPTIONS
- Custom methods
- application/json
- application/xml
- application/x-www-form-urlencoded
- multipart/form-data
- Path matching (exact, prefix, regex)
- Query parameter handling
- Header manipulation
- Body transformation
- Host-based routing
- Method-based routing
HTTP Routing Configuration
client_route:
path: /api/v1/*
method: GET, POST, PUT, DELETE
protocol: https
port: 443
upstream_target:
url: http://backend-service:8080
protocol: http
HTTP Routing Usage Scenarios
- REST API Gateway: Management of REST APIs
- API Versioning: API versioning
- Legacy System Integration: Integration with legacy systems
- Public API Exposure: Exposing APIs to the outside world
For detailed information, see the HTTP Routing page.