New Laravel package lets Inertia and JSON API responses share one controller
A developer has released 'inertia-split', an open-source Laravel package designed to eliminate the friction of running InertiaJS alongside a traditional JSON API. The package allows a single controller method to automatically return an Inertia component response or a JSON response depending on the type of incoming request, without requiring manual checks in the code. It offers two integration approaches: a trait-based method using a respond() helper, and a simpler attribute annotation that makes existing API methods Inertia-aware with minimal changes. An opt-in service provider binding replaces Inertia's default ResponseFactory with a hybrid version that handles response routing via polymorphism. The package is currently in beta and is available on GitHub under the repository EmilienKopp/inertia-split.
This is an AI-generated summary. ShortSingh links to the original source for the complete article.
Discussion (0)
Log in to join the discussion and vote.
Log in