Weave 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
Dingo Serializer Switch

Dingo Serializer Switch Laravel Package

liyu/dingo-serializer-switch

Per-request serializer switching for Dingo API in Laravel. Clients choose array, JSON, or custom serializers via header or query parameter, letting one API serve multiple response formats without config changes or extra controllers.

View on GitHub
Deep Wiki
Context7

A middleware to switch dingo serializer

Frequently asked questions about Dingo Serializer Switch
What does liyu/dingo-serializer-switch do?
It is a thin Laravel middleware that switches the Dingo API serializer on a per-request or per-route basis. Instead of hard-coding one serializer in Dingo config, clients can request array, JSON, or a custom serializer through a header or query parameter. This lets a single Dingo API serve multiple response formats without extra controllers or config edits.
How do I install liyu/dingo-serializer-switch in a Laravel app?
Add the package with Composer and register the middleware in your Laravel HTTP kernel or directly on the Dingo route groups where switching should be allowed. Then define the serializer-selection contract your clients will use. Because the package is small and older, run a short non-production spike to confirm installation, middleware ordering, and response behavior before rolling it out.
How does a client choose which serializer to use?
Clients select a serializer via an HTTP header or a query parameter, based on how you wire the middleware into your routes. You should document the exact header name or query key and the accepted values for your API consumers. Also decide what happens when the value is missing or invalid, such as falling back to Dingo's default serializer.
Which serializers are supported by this package?
The middleware is designed to switch between Dingo API serializers such as array, JSON, and custom serializer classes you have configured. The exact supported set depends on your Dingo version and on how the middleware resolves the requested value. Confirm which serializer classes your Dingo installation provides before exposing them to clients.
Do I need Dingo API to use this package?
Yes. This package is an extension for Dingo API and is not useful for Laravel-native APIs that do not use Dingo. If you are on standard Laravel routing, use Eloquent API Resources or a custom response middleware instead. It is best treated as a tactical compatibility shim inside an existing Dingo codebase.
Which PHP, Laravel, and Dingo API versions are supported?
The package targets the older Dingo ecosystem, so you should verify Composer constraints against your current PHP, Laravel, and Dingo versions before adopting it. Check the repository's composer.json and run a dependency resolution test in a branch. If constraints conflict, fork the middleware into your application namespace rather than forcing an install.
Does serializer switching affect pagination, error responses, and transformers?
Yes, potentially. Changing the serializer can change the response envelope for paginated results, errors, and transformed models, which can break clients that expect one consistent shape. Add contract tests for success, error, pagination, and transformation responses and compare each serializer's output against your default. Keep one documented fallback serializer for clients that do not opt in.
Is liyu/dingo-serializer-switch actively maintained?
The project has modest adoption, around 48 stars and no known dependents, and is likely maintained by a single owner. The MIT license is favorable and allows you to fork, vendor, or internalize the middleware if it becomes stale. Assign an internal owner, pin the version, and treat Dingo upgrades as breaking-change events.
How should I test serializer switching before production?
Pilot the middleware on one low-risk route group in a non-production environment first. Register it, map client request types to serializers, and add automated response-contract tests covering success, error, pagination, and transformation output. Instrument serializer usage and errors, then expand route group by route group with a default fallback.
What caching or scalability issues should I watch for?
Runtime overhead from the middleware is likely negligible, but serializer choice can change payload shape, size, and CPU cost. Make sure any response cache keys include the selected serializer, otherwise clients may receive the wrong format. Load-test high-volume endpoints with each supported serializer before broad rollout.
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.
coleus/frame
thtg88/journalism
filagora/filagora-ai-forums
rlacerda83/query-parser
socialdept/atp-orm
cboxdk/laravel-assistant-client
socialdept/atp-resolver
socialdept/tenant-domains
tautvydasr/blade-class-names
socialdept/color-scales
maherelgamil/controller
coleus/widgets
coleus/table
coleus/users
coleus/music
coleus/health
coleus/calendar
coleus/notes
coleus/support
coleus/settings