Skip to content

ApiGateway

Sebastián Richiardi edited this page Jul 1, 2025 · 2 revisions

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 retries
  • Http::apiGatewayDirect() – same but without retries
  • Http::apiGatewayWithToken($token) – authenticated requests
  • Http::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.

Clone this wiki locally