API Proxy Design
1. Overview
The Registration Portal operates as a JHipster gateway application, proxying most API requests to the admin-service backend. This design provides a clean separation between the presentation layer (Angular) and the business logic layer (Spring Boot services).
Key Benefits:
-
Single Entry Point - All API calls go through gateway
-
Security Layer - Token validation at gateway
-
Service Discovery - Gateway routes requests to correct service
-
Load Balancing - Can distribute requests across service instances
-
Circuit Breaking - Fault tolerance for backend failures
3. Gateway Routes Configuration
3.1. Route Definitions
spring:
cloud:
gateway:
routes:
- id: admin-service
uri: http://localhost:8080
predicates:
- Path=/api/**,/services/**
filters:
- RewritePath=/(?<segment>.*), /$\{segment}
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY,GATEWAY_TIMEOUT
methods: GET,POST,PUT,DELETE
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
basedOnPreviousValue: false
- id: admin-service-websocket
uri: ws://localhost:8080
predicates:
- Path=/websocket/**
4. Development Configuration
4.1. Static Routes
It is possible to override the Cloud Gateway functionality by providing static routes. This can be useful during development when you want to route to a locally running admin-service instance.
cloud:
gateway:
routes:
- id: admin-service
uri: http://localhost:12504
predicates:
- Path=/services/admin-service/**
filters:
- RewritePath=/services/admin-service/(?<segment>.*), /$\{segment}
The routes key contains an array of objects to define each possible route.
The predicates section defines elements of the search request to be matched. In this case the Path is used. The filters section also lists a rewrite instruction to strip the first part of the path, /services/admin-service/. For instance:
/services/admin-service/acme
is replaced by:
/acme
5. Proxied Endpoints
5.1. Person API
| Method | Frontend Path | Proxied To | Service |
|---|---|---|---|
GET |
|
admin-service |
PersonService |
POST |
|
admin-service |
PersonService |
PUT |
|
admin-service |
PersonService |
DELETE |
|
admin-service |
PersonService |
GET |
|
admin-service |
PersonService |
POST |
|
admin-service |
PersonService |
5.2. LinkedPerson API
| Method | Frontend Path | Proxied To | Service |
|---|---|---|---|
POST |
|
admin-service |
LinkedPersonService |
GET |
|
admin-service |
LinkedPersonService |
DELETE |
|
admin-service |
LinkedPersonService |
5.3. Form/Process API
| Method | Frontend Path | Proxied To | Service |
|---|---|---|---|
GET |
|
admin-service |
FormService |
POST |
|
admin-service |
FormService |
POST |
|
admin-service |
ProcessService |
POST |
|
admin-service |
ProcessService |
6. Local Gateway Endpoints
7. Service Configuration
7.1. ApplicationConfigService
The Angular application uses ApplicationConfigService to construct proxied endpoint URLs:
@Injectable({ providedIn: 'root' })
export class ApplicationConfigService {
private endpointPrefix = '';
setEndpointPrefix(endpointPrefix: string): void {
this.endpointPrefix = endpointPrefix;
}
getEndpointFor(api: string, microservice?: string): string {
if (microservice) {
return `${this.endpointPrefix}services/${microservice}/${api}`;
}
return `${this.endpointPrefix}${api}`;
}
}
Usage Examples:
// Proxied to admin-service
this.applicationConfigService.getEndpointFor('api/people', 'admin-service')
// Returns: "services/admin-service/api/people"
// Direct gateway endpoint
this.applicationConfigService.getEndpointFor('api/account')
// Returns: "api/account"
9. Error Handling
9.1. Circuit Breaker
The gateway includes circuit breaker patterns for fault tolerance:
Configuration:
resilience4j:
circuitbreaker:
instances:
admin-service:
failureRateThreshold: 50
waitDurationInOpenState: 10s
slidingWindowSize: 10
minimumNumberOfCalls: 5
Behavior:
-
Closed - Normal operation, requests flow through
-
Open - Too many failures, requests immediately fail with 503
-
Half-Open - Testing if service recovered, limited requests allowed
9.2. Retry Logic
filters:
- name: Retry
args:
retries: 3
statuses: BAD_GATEWAY,GATEWAY_TIMEOUT
methods: GET,POST,PUT,DELETE
backoff:
firstBackoff: 10ms
maxBackoff: 50ms
factor: 2
Retry Scenarios:
-
502 Bad Gateway - Backend unreachable
-
504 Gateway Timeout - Backend slow to respond
-
Exponential backoff between retries
10. Security Integration
10.1. Request Headers
Outbound Headers (Angular → Gateway):
Accept-Language: en
Content-Type: application/json
X-TENANT-ID: 5 // Optional: For programmatic/API access
Tenant Resolution Headers:
The gateway supports tenant identification via the X-TENANT-ID header for programmatic access:
| Header | Format | Example |
|---|---|---|
X-TENANT-ID |
Numeric tenant ID (Long) |
|
Priority:
-
URL subdomain (e.g.,
runningclub.example.com) -
X-TENANT-ID header