Weave Code
Code Weaver
Helps Laravel developers discover, compare, and choose open-source packages. See popularity, security, maintainers, and scores at a glance to make better decisions.
Feedback
Share your thoughts, report bugs, or suggest improvements.
Subject
Message

Apitoolkit Symfony Laravel Package

apitoolkit/apitoolkit-symfony

View on GitHub
Deep Wiki
Context7

Getting Started

Minimal Setup

  1. Install the package:
    composer require apitoolkit/apitoolkit-symfony
    
  2. Add API key to .env:
    APITOOLKIT_KEY=your_api_key_here
    
  3. Register the event subscriber in config/services.yaml:
    services:
        APIToolkit\EventSubscriber\APIToolkitService:
            arguments:
                $apiKey: '%env(APITOOLKIT_KEY)%'
    
  4. Enable the subscriber in config/packages/framework.yaml:
    framework:
        event_dispatcher:
            subscribers:
                - APIToolkit\EventSubscriber\APIToolkitService
    

First Use Case: Monitoring API Traffic

  • No code changes required—the SDK automatically captures HTTP requests/responses via Symfony’s event system.
  • Verify traffic appears in the APItoolkit dashboard.

Implementation Patterns

Core Workflow: Request/Response Tracking

  1. Automatic Capture:

    • The APIToolkitService subscribes to Kernel::REQUEST and Kernel::RESPONSE events.
    • No manual instrumentation needed for standard Symfony HTTP requests.
  2. Custom Endpoints:

    • For non-HTTP logic (e.g., CLI commands, background jobs), manually trigger events:
      use APIToolkit\EventSubscriber\APIToolkitEvents;
      
      $dispatcher->dispatch(new APIToolkitEvents\RequestEvent(
          'custom/endpoint',
          $requestData,
          $metadata
      ));
      
  3. Contextual Data:

    • Attach metadata (e.g., user IDs, request IDs) via RequestEvent:
      $event = new APIToolkitEvents\RequestEvent('user/profile', ['id' => 123]);
      $event->setMetadata(['user_id' => 123, 'source' => 'mobile']);
      $dispatcher->dispatch($event);
      

Integration Tips

  • API Versioning: Prefix endpoints with /v1/ or similar to distinguish versions in the dashboard.
  • Error Handling: Use APIToolkitEvents::ErrorEvent for exceptions:
    $dispatcher->dispatch(new APIToolkitEvents\ErrorEvent(
        $exception,
        ['endpoint' => 'user/login', 'status' => 500]
    ));
    
  • Redacting Sensitive Data: Configure in config/packages/apitoolkit.yaml (if available) or via environment variables:
    APITOOLKIT_REDACT_FIELDS=password,token,credit_card
    

Gotchas and Tips

Pitfalls

  1. Event Dispatcher Timing:

    • Ensure the subscriber is registered before the Kernel::REQUEST event is dispatched.
    • Debug with bin/console debug:event-dispatcher to verify subscriber order.
  2. Environment Variables:

    • The SDK requires APITOOLKIT_KEY—missing keys cause silent failures. Validate with:
      php bin/console debug:container APIToolkit\EventSubscriber\APIToolkitService
      
      (Check for null in $apiKey.)
  3. Non-HTTP Traffic:

    • CLI commands or queue workers won’t auto-capture. Manually dispatch events as shown above.
  4. Payload Size Limits:

    • Large responses (>1MB) may be truncated. Use setMaxPayloadSize() in the subscriber if needed:
      $service->setMaxPayloadSize(2097152); // 2MB
      

Debugging

  • Log Events: Enable Symfony’s profiler (APP_DEBUG=1) to inspect dispatched events.
  • Network Issues: The SDK uses HTTP to send data to APItoolkit. Check CURL errors with:
    $service->setDebugMode(true); // Logs HTTP errors to Symfony’s logger.
    

Extension Points

  1. Custom Payload Transformers: Override APIToolkit\PayloadTransformer\DefaultTransformer to modify request/response data before sending:

    services:
        APIToolkit\PayloadTransformer\DefaultTransformer:
            class: App\CustomTransformer
    
  2. Batch Processing: For high-throughput apps, configure batching via environment variables:

    APITOOLKIT_BATCH_SIZE=50
    APITOOLKIT_BATCH_TIMEOUT=30
    
  3. Local Development: Disable the SDK in config/packages/dev/apitoolkit.yaml:

    api_toolkit:
        enabled: false
    
Weaver

How can I help you explore Laravel packages today?

Conversation history is not saved when not logged in.
Prompt
Add packages to context
No packages found.
comsave/common
alecsammon/php-raml-parser
chrome-php/wrench
lendable/composer-license-checker
typhoon/reflection
mesilov/moneyphp-percentage
mike42/gfx-php
bookdown/themes
aura/view
aura/html
aura/cli
povils/phpmnd
nayjest/manipulator
omnipay/tests
psr-mock/http-message-implementation
psr-mock/http-factory-implementation
psr-mock/http-client-implementation
voku/email-check
voku/urlify
rtheunissen/guzzle-log-middleware