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

Api Gateway Bundle Laravel Package

demroos/api-gateway-bundle

View on GitHub
Deep Wiki
Context7
## Getting Started
Install the package via Composer:
```bash
composer require vendor/api-gateway-package

Publish the configuration (if needed):

php artisan vendor:publish --provider="Vendor\ApiGatewayPackage\ApiGatewayServiceProvider"

Register the service provider in config/app.php under providers.

First Use Case: Listen to the new api_gateway.endpoint.request and api_gateway.endpoint.response events to intercept and modify API gateway requests/responses. Example:

use Vendor\ApiGatewayPackage\Events\EndpointRequestEvent;
use Vendor\ApiGatewayPackage\Events\EndpointResponseEvent;

Event::listen(EndpointRequestEvent::class, function (EndpointRequestEvent $event) {
    // Modify request data before it reaches the gateway
    $event->request->merge(['custom_header' => 'value']);
});

Event::listen(EndpointResponseEvent::class, function (EndpointResponseEvent $event) {
    // Transform response data
    $event->response->setData(['modified' => true]);
});

Implementation Patterns

Event-Driven Workflows

Leverage the new events for:

  • Request Interception: Validate, enrich, or log incoming requests.
  • Response Transformation: Modify payloads, add metadata, or enforce policies.
  • Middleware-Like Logic: Use events instead of traditional middleware for gateway-specific logic.

Integration with Existing Code

Pair with Laravel’s built-in Event facade or use a package like spatie/laravel-event-sourcing for advanced workflows.

Example: Logging All Gateway Traffic

Event::listen(EndpointRequestEvent::class, function ($event) {
    \Log::info('API Gateway Request', [
        'endpoint' => $event->endpoint,
        'data' => $event->request->all(),
    ]);
});

Event::listen(EndpointResponseEvent::class, function ($event) {
    \Log::info('API Gateway Response', [
        'endpoint' => $event->endpoint,
        'status' => $event->response->status(),
    ]);
});

Gotchas and Tips

Event Ordering

  • api_gateway.endpoint.request fires before the gateway processes the request.
  • api_gateway.endpoint.response fires after the gateway generates a response.
  • Avoid infinite loops by not modifying $event->request or $event->response in a way that triggers another event.

Performance Considerations

  • Heavy transformations in event listeners may slow down request/response cycles.
  • Use Event::until() or Event::unless() to scope listeners to specific endpoints:
    Event::listen(EndpointRequestEvent::class, function ($event) {
        // Only run for '/admin/*' endpoints
    })->until(fn ($event) => str_starts_with($event->endpoint, '/admin'));
    

Debugging

  • Check if events are firing by logging in listeners or using php artisan event:list.
  • Ensure the package’s service provider is registered (verify config/app.php).

Extension Points

  • Custom Events: Extend the package by creating your own events (e.g., api_gateway.endpoint.error).
  • Service Providers: Override the package’s default behavior by binding your own implementations of the gateway interface.

NO_UPDATE_NEEDED (for prior assessment, as this is the first version).
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.
directorytree/privacy-filter-classifier
directorytree/privacy-filter
datacore/hub-sdk
develia/commons
cuci/prototurk-sdk
cuci/prototurk-sdk-symfony
develia/geo-bundle
dreamzy/livewire-charts
touchestate-sdk/php-sdk
22h/doctrine-garbage-collection-bundle
agtp/agtp-php
agtp/mod-php
splash/sonata-admin
splash/metadata
splash/openapi
splash/scopes
splash/toolkit
testo/output-teamcity
testo/bridge-symfony
spatie/flare-daemon-runtime