composer require apitoolkit/apitoolkit-symfony
.env:
APITOOLKIT_KEY=your_api_key_here
config/services.yaml:
services:
APIToolkit\EventSubscriber\APIToolkitService:
arguments:
$apiKey: '%env(APITOOLKIT_KEY)%'
config/packages/framework.yaml:
framework:
event_dispatcher:
subscribers:
- APIToolkit\EventSubscriber\APIToolkitService
Automatic Capture:
APIToolkitService subscribes to Kernel::REQUEST and Kernel::RESPONSE events.Custom Endpoints:
use APIToolkit\EventSubscriber\APIToolkitEvents;
$dispatcher->dispatch(new APIToolkitEvents\RequestEvent(
'custom/endpoint',
$requestData,
$metadata
));
Contextual Data:
RequestEvent:
$event = new APIToolkitEvents\RequestEvent('user/profile', ['id' => 123]);
$event->setMetadata(['user_id' => 123, 'source' => 'mobile']);
$dispatcher->dispatch($event);
/v1/ or similar to distinguish versions in the dashboard.APIToolkitEvents::ErrorEvent for exceptions:
$dispatcher->dispatch(new APIToolkitEvents\ErrorEvent(
$exception,
['endpoint' => 'user/login', 'status' => 500]
));
config/packages/apitoolkit.yaml (if available) or via environment variables:
APITOOLKIT_REDACT_FIELDS=password,token,credit_card
Event Dispatcher Timing:
Kernel::REQUEST event is dispatched.bin/console debug:event-dispatcher to verify subscriber order.Environment Variables:
APITOOLKIT_KEY—missing keys cause silent failures. Validate with:
php bin/console debug:container APIToolkit\EventSubscriber\APIToolkitService
(Check for null in $apiKey.)Non-HTTP Traffic:
Payload Size Limits:
setMaxPayloadSize() in the subscriber if needed:
$service->setMaxPayloadSize(2097152); // 2MB
APP_DEBUG=1) to inspect dispatched events.$service->setDebugMode(true); // Logs HTTP errors to Symfony’s logger.
Custom Payload Transformers:
Override APIToolkit\PayloadTransformer\DefaultTransformer to modify request/response data before sending:
services:
APIToolkit\PayloadTransformer\DefaultTransformer:
class: App\CustomTransformer
Batch Processing: For high-throughput apps, configure batching via environment variables:
APITOOLKIT_BATCH_SIZE=50
APITOOLKIT_BATCH_TIMEOUT=30
Local Development:
Disable the SDK in config/packages/dev/apitoolkit.yaml:
api_toolkit:
enabled: false
How can I help you explore Laravel packages today?