PHP code example of oluokunkabiru / api-call-logger
1. Go to this page and download the library: Download oluokunkabiru/api-call-logger library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
Http::withApiLogging('gobeller', 'create-wallet', [
'loggable' => $transaction, // link the log to a local model
'tenant' => $institution->code, // override the tenant for this call
'meta' => ['wallet_type' => 'savings'], // anything extra
'success' => fn ($response) => (bool) $response->json('status'), // providers that return 200 + status:false
])->post(...);
// The provider comes from the segment after "webhooks": /api/webhooks/flutterwave → flutterwave
Route::prefix('webhooks')->middleware('api-call-logger.inbound')->group(function () {
Route::post('flutterwave', FlutterwaveWebhookController::class);
Route::post('fyatu', FyatuWebhookController::class);
});
// Or give the provider (and context) explicitly
Route::post('paystack/callback', ...)->middleware('api-call-logger.inbound:paystack,charge-success');
use Oluokunkabiru\ApiCallLogger\Facades\ApiCallLogger;
ApiCallLogger::log(
provider: 'gobeller',
method: 'POST',
url: $this->baseUrl . $endpoint,
request: $payload, // array or raw string (JSON / form decoded automatically)
response: $responseBody,
status: $statusCode, // null for connection failures
success: $success, // defaults to 2xx
durationMs: $durationMs,
context: 'self-service',
requestHeaders: $headers,
responseHeaders: $responseHeaders,
loggable: $transaction,
);
// Or let the package time it for you:
$result = ApiCallLogger::measure('bank-soap', 'POST', $wsdl, fn () => $client->Transfer($args), request: $args);
ApiCallLogger::withTenant($request->header('X-Institution-Code'));
ApiCallLogger::withMeta(['channel' => 'mobile']);
// Or resolve them lazily, in a service provider:
ApiCallLogger::resolveTenantUsing(fn () => request()->attributes->get('institution')?->code);
ApiCallLogger::resolveUserUsing(fn () => auth('admin')->id()); // default: auth()->id()