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

Rest Routing Bundle Laravel Package

handcraftedinthealps/rest-routing-bundle

Symfony bundle that restores FOSRestBundle-style automatic REST route generation. Supports format options and method/name prefixing, and includes a command to dump/convert type: rest routes into standard Symfony routes for migration or opt-out.

View on GitHub
Deep Wiki
Context7

Technical Evaluation

Architecture Fit

  • Replaces FOSRestBundle 3.0’s routing with a drop-in alternative, maintaining RESTful conventions (@RouteResource, @Prefix, etc.).
  • Annotation-driven (similar to Symfony’s native routing) but optimized for REST APIs, reducing boilerplate.
  • Symfony 6/7/8 compatible, with explicit support for PHP 8.1–8.4 (critical for modern Laravel/PHP stacks).
  • Decoupled from FOSRestBundle’s full stack, allowing selective adoption (e.g., routing without FOS’s view handlers).

Key Fit for Laravel/PHP Ecosystem:

  • Aligns with Symfony’s routing philosophy, easing integration into Laravel’s Symfony-based components (e.g., symfony/http-foundation).
  • No Laravel-specific dependencies, but leverages Symfony’s AnnotationReader and Routing components—common in Laravel’s service containers.

Integration Feasibility

  • Low-risk for existing Symfony/Laravel apps using FOSRestBundle 2.x or manual REST routing.
  • Migration path provided:
    • Replace FOS\RestBundle\Routing\ClassResourceInterface with the bundle’s equivalent.
    • Update annotations (@RouteResource, @Prefix, etc.) to the new namespace.
    • Zero-config migration if using identical FOSRestBundle 3.0 settings.
  • Laravel-specific considerations:
    • Laravel’s route caching (php artisan route:cache) may need adjustment if routes are dynamically generated.
    • Service container conflicts: Laravel’s Illuminate\Container vs. Symfony’s DependencyInjection require explicit binding (e.g., via AppServiceProvider).

Technical Risks:

  1. Annotation parsing conflicts: Laravel’s RouteServiceProvider vs. Symfony’s AnnotationLoader.
    • Mitigation: Use Laravel’s Route::getRoutes() to merge routes post-load.
  2. Performance overhead: Dynamic route generation adds ~5–10ms per request (benchmark in staging).
  3. Deprecation warnings: PHP 8.4’s nullable objects may trigger false positives if not updated (fixed in v1.1.2+).

Key Questions for TPM

  1. Why migrate from FOSRestBundle 3.0?
    • Is the goal to reduce bundle bloat (FOSRestBundle is heavy) or avoid FOS’s licensing?
    • Does the team need FOS’s view handlers (e.g., ViewHandler) or only routing?
  2. Laravel-Symfony hybrid impact:
    • How will this interact with Laravel’s Route facade and apiResource() helpers?
    • Will routes be preloaded (Laravel’s default) or dynamically generated (Symfony’s default)?
  3. Long-term maintenance:
    • The bundle’s official recommendation is to opt out (v1.2.0+). Is this a temporary solution?
    • Are there plans to native Laravel support (e.g., a Laravel-specific adapter)?

Integration Approach

Stack Fit

  • Primary Use Case: Laravel apps using Symfony components (e.g., symfony/routing, symfony/http-kernel) or migrating from FOSRestBundle.
  • Alternatives Considered:
    • Native Laravel: apiResource() + manual routes (less flexible for complex REST APIs).
    • API Platform: Overkill for simple REST routing.
    • FOSRestBundle 3.0: Retain full feature set (but heavier).
  • Best Fit: Apps needing REST conventions without FOS’s dependencies (e.g., view handlers, format listeners).

Migration Path

Step Action Tools/Commands
1 Assess Dependency Graph composer why-not handcraftedinthealps/rest-routing-bundle
2 Replace Annotations Update use statements (see README diff example).
3 Update Config Replace fos_rest.routing_loader with handcraftedinthealps_rest_routing.
4 Test Route Generation php artisan route:list (Laravel) or bin/console debug:router (Symfony).
5 Opt-Out (If Needed) bin/console fos:rest:routing:dump-symfony-routes → paste into routes/api.php.
6 Benchmark Compare route load times with/without the bundle.

Laravel-Specific Steps:

  • Register the bundle in config/app.php under extra.bundles.
  • Override Symfony’s AnnotationReader in AppServiceProvider to avoid conflicts:
    public function register()
    {
        $this->app->singleton(\Symfony\Component\DependencyInjection\Loader\AnnotationReader::class);
    }
    

Compatibility

Component Compatibility Notes
Symfony 6/7/8 ✅ Full Tested in CI.
PHP 8.1–8.4 ✅ Full PHP 8.4 deprecations fixed in v1.1.2.
Laravel 9/10 ⚠️ Partial Requires Symfony components; may conflict with Laravel’s Route facade.
FOSRestBundle 3.0 ✅ Drop-in Identical config structure.
Doctrine Annotations Uses doctrine/annotations v1.4+.

Breaking Changes:

  • No FOS\RestBundle namespace imports allowed (must use HandcraftedInTheAlps\RestRoutingBundle).
  • Route namespacing: Prefixes like @Prefix("/api") are preserved but must match Symfony’s conventions.

Sequencing

  1. Phase 1: Pilot Module
    • Isolate a non-critical API module (e.g., /admin routes).
    • Replace FOS annotations → test with route:list.
  2. Phase 2: Full Migration
    • Update all controllers → regenerate routes.
    • Avoid mixing old FOS and new annotations in the same app.
  3. Phase 3: Opt-Out (If Chosen)
    • Use dump-symfony-routes to convert to manual routes/api.php definitions.

Rollback Plan:

  • Keep a backup of routes/api.php or use Git to revert annotations.
  • Fallback to manual route definitions if dynamic generation fails.

Operational Impact

Maintenance

  • Pros:
    • No vendor lock-in: MIT license, no FOSRestBundle dependencies.
    • Active development: 6 releases in 2024–2025, PHP 8.4 support.
    • Self-contained: Only affects routing; no impact on views, serializers, etc.
  • Cons:
    • Symfony-specific: Requires familiarity with Symfony’s DI container.
    • Laravel overhead: May need custom service bindings.
  • Maintenance Tasks:
    • Monitor for Symfony 8.x deprecations (next major version).
    • Update doctrine/annotations if Laravel’s version drifts.

Support

  • Documentation: Good (RST docs, clear migration guide).
  • Community: Limited (58 stars, but active maintainers).
  • Debugging:
    • Use bin/console debug:router to inspect generated routes.
    • Check Symfony’s EventDispatcher logs for route loading errors.
  • Laravel-Specific Support:
    • No official Laravel docs → rely on Symfony’s Routing component docs.
    • Stack Overflow tags: symfony-routing, laravel-symfony.

Scaling

  • Performance:
    • Dynamic route generation adds ~5–10ms per request (benchmark in staging).
    • Caching: Laravel’s route:cache will cache generated routes (mitigates overhead).
  • High Traffic:
    • No known bottlenecks in the bundle itself (risk lies in Symfony’s AnnotationReader).
    • Recommendation: Use opcache + Laravel’s route cache.
  • Horizontal Scaling:
    • Stateless → scales like any Symfony/Laravel app.
    • No shared state between instances.

Failure Modes

Failure Scenario Impact Mitigation
Annotation parsing errors Routes fail to load → 500 errors. Validate annotations with php artisan route:list.
Symfony DI conflicts Laravel’s container rejects Symfony services. Explicitly bind AnnotationReader in AppServiceProvider.
Route name collisions Duplicate routes (e.g., /api/users from two controllers). Use @NamePrefix to scope routes.
PHP 8.4 deprecations Nullable object warnings. Upgrade to v1.1.2+.
Laravel cache corruption route:cache fails
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.
graham-campbell/flysystem
capell-app/block-library
axium/identity
cetria/laravel-dummy-models
cetria/reflection-helper
agropredict/sso-auth-bundle
evolvestudio/spam-protection
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