gateway:
prefix: /api
host: https://arsiteknologi.com:8080
trusted_ips: ['127.0.0.1', '::1']
exclude_paths:
- /public/settings
auth:
host: https://arsiteknologi.com:8080
login:
path: /login
method: POST
credential:
type: json
username:
field: username
value: admin
password:
field: password
value: admin
verify_path: /me #mostly profile path
token:
key: token
lifetime: 3600
prefixis the prefix of url for all services and routes. Set to null or empty string if want to avoid it.
hostis global host. if you don't set the host in auth or services, it value will be applied.
trusted_ipsare ip list that have special policy such as no request limit and auto login when call private URL without any credential.
exclude_pathsare path(s) that no request limiter applied. It mean, we don't limit request to these resources.
auth.host(optional) is the host of authentication service. if not set, global host will be applied.
auth.loginis the login path and method. the prefix added to login path.
auth.credentialare credentnial to supply when login called.
auth.verify_pathis path that will check the token is valid or not. Basically all private page can used here.
auth.tokenis config to tell how to get the token from response. ex:{ token: 'thisIsSecretToken'}, so the key istoken.
gateway:
routes:
route1:
path: /me
methods: [GET]
priority: 0
public: false
cache_lifetime: 5
balance: roundrobin # roundrobin | random | sticky (master/slave) NB: Please noted, some balance method may not work during development
timeout: 0
handlers:
- service1
- service2
route1is route name
pathis route path. Will be appended with prefix if prefix is set
methodsis route methods
priorityis route priority that follow the symfony route priority
publicis mark the route as public or private route
cache_lifetimeis cache lifetime in second
balanceis load balancer method that use in route. default roundrobin
timeoutis how long we will wait the service until returning response
handlersare list of service to handle this route
gateway:
services:
service1:
host: https://arsiteknologi.com:8080
health_check_path: /status
version: v1
limit: 1000
weight: 3
service1is service name
host(optional) is hos of service. if not set, global host will be applied.
health_check_pathis path that indicate the service is up. Just return 200 to indicate service is available.
versionis prefix version for service that applied to route.
limitis limit service to call if this limit reached the service is no available to give time the service to recover it self and then counter will be resetted.
weightis service weight when using weight method as balance method
gateway:
aggregates:
customer_order:
path: /customer_orders/{customerId}
priority: 0
cache_lifetime: 5
handler: 'KejawenLab\SemartApiGateway\Aggregate\CustomerOrder'
customer_orderis aggregate name
pathis route path. Will be appended with prefix if prefix is set
priorityis route priority that follow the symfony route priority
cache_lifetimeis cache lifetime in second
handleris class to handle this aggregate query. The class must implementKejawenLab\SemartApiGateway\Aggregate\AggregateRequestInterfaceinterface. If class has dependencies in constructor, add this class to container.
<?php
declare(strict_types=1);
namespace KejawenLab\SemartApiGateway\Aggregate;
use Symfony\Component\HttpClient\HttpClient;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
class CustomerOrder implements AggregateRequestInterface
{
public function handle(Request $request): Response
{
$customerOrders = [];
$client = HttpClient::create();
//Do stuff here like call Api that you need to aggregate
return new JsonResponse(['customer_orders' => $customerOrders]);
}
}containers:
KejawenLab\SemartApiGateway\Aggregate:
- 'Other\Service\Class'
- 'staticParameter'Just two simple step to create aggregate query handler, very simple, isn't it?