ApiGateway - KroderDev/laravel-microservice-core GitHub Wiki
Configuration and helpers for communicating with your gateway service.
Configuration
Set the base URL of your gateway in config/microservice.php
:
'api_gateway' => [
'url' => env('API_GATEWAY_URL', 'http://gateway.local'),
],
HTTP Client Macros
The service provider registers four macros on Laravel's HTTP client. They all forward the current correlation ID header.
Http::apiGateway()
– default options with retriesHttp::apiGatewayDirect()
– same but without retriesHttp::apiGatewayWithToken($token)
– authenticated requestsHttp::apiGatewayDirectWithToken($token)
– authenticated without retries
See Http-Client-Macros for exception handling details.
ApiGatewayClient
Kroderdev\LaravelMicroserviceCore\Services\ApiGatewayClient
wraps these macros with convenient get
, post
, put
and delete
methods:
use Kroderdev\LaravelMicroserviceCore\Services\ApiGatewayClient;
$response = ApiGatewayClient::make()->get('/users');
A factory is bound for dependency injection so you can type-hint ApiGatewayClient
or ApiGatewayClientInterface
in your services.
HTTP Client Macros
Use Http::apiGateway()
and related macros for service-to-service calls. Each macro automatically forwards the current correlation ID.
Errors returned by the gateway throw an ApiGatewayException
with the same status code.