Why I Chose Inertia.js Over a Separate API Layer for Laravel

Software Engineer Dublin

Software Engineer Dublin

Engineer Built To Scale

Beyond The Code

What They Say

Let's Build

Message Received

Privacy Policy

Terms Of Use

Cookie Policy

Disclaimer

Latest Updates

Selected Work

Showcase

What We Offer

Industries We Serve

Beyond The Screen

Built Together

View View
Nben Malla
Nben Malla

Software Engineer

Nben Malla is a software engineer based in Dublin, Ireland, specializing in microservices architecture, legacy system modernization and full stack development.

With experience across FinTech and SaaS, he has delivered scalable backend systems for global clients using Go, Java, Python, Django and Laravel, collaborating with teams across Nepal, Ireland, the Netherlands, New Zealand and the United States.

From leading legacy modernization for global banking clients to architecting microservices and distributed systems, the focus has always been to understand the problem deeply, build it right and deliver software that lasts.

  • Read Article Read Article

    Packages 7 mins

    Why I Chose Inertia.js Over a Separate API Layer for Laravel

    Nben Malla 18 Nov, 2026 7 mins

    Why I Chose Inertia.js Over a Separate API Layer for Laravel

    The first version of the frontend for my Laravel SaaS product was a Vue single page app talking to a versioned JSON API. It followed the pattern every conference talk recommends: Sanctum tokens, resource classes, a typed client, and a clean separation between layers. Within four months, I maintained two codebases, two validation layers, and a growing list of bugs that lived between them.

    The worst bug came from a renamed field. I changed a column name in a resource class, updated the Laravel tests, and shipped. The invoice screen kept loading and showed blank totals, because nothing connected the response shape to the component that read it.

    I rebuilt the frontend with Inertia.js and kept Laravel as the single application. This article explains why I chose it, what it removed, and where I accepted tradeoffs.

    The Cost of a Separate API Layer

    A separate API layer is a product with its own users, and the first user is your frontend. It needs versioning, documentation, error formats, pagination conventions, and a deprecation policy. For a public platform, that cost buys real value. For a frontend that one team ships together with the backend, it buys very little.

    The API layer also duplicates decisions. Authorization lives in policies on the server and again in conditional rendering on the client. Validation lives in form requests and again in a client schema. Every duplicated rule can drift, and I fixed the same drift bug three times in one quarter.

    Sponsor Ads

    Authentication added a third cost. Token handling, refresh logic, CORS configuration, and cookie settings across subdomains consumed more of my time than any feature. None of that work made the product better for customers.

    What Inertia Changes

    Inertia removes the API between Laravel and the frontend while keeping a component based frontend. A controller returns a page component name and props, and Inertia renders the Vue or React component with those props. Navigation happens through XHR visits that swap the component, so the app feels like a single page app without a client router or an API client.

    php
    class InvoiceController extends Controller
    {
        public function index(Request $request): Response
        {
            $this->authorize('viewAny', Invoice::class);
    
            return Inertia::render('Invoices/Index', [
                'invoices' => InvoiceResource::collection(
                    Invoice::query()
                        ->where('tenant_id', $request->user()->tenant_id)
                        ->latest()
                        ->paginate(20)
                ),
                'filters' => $request->only('status'),
            ]);
        }
    }
    html
    <script setup>
    defineProps({ invoices: Object, filters: Object })
    </script>
    
    <template>
      <InvoiceTable :rows="invoices.data" />
    </template>

    The controller is a normal Laravel controller. Routing, middleware, policies, form requests, and resources all work the way they did before. I deleted the client router, the HTTP client wrapper, and the token storage code in one week.

    The mental model also simplifies. A page is a route plus props, and a form is a post to a route. I explain the whole architecture to a new engineer in ten minutes, which never worked with the API version.

    Authentication and Authorization Stay in One Place

    Inertia uses the session and cookie authentication that Laravel already provides. There are no tokens to store, rotate, or leak into local storage. The browser sends the session cookie, middleware checks it, and the request proceeds like any other web request.

    Authorization travels through shared props. I compute permissions on the server and send the results to the client, so the client never decides what a user may do. It displays what the server already decided.

    php
    public function share(Request $request): array
    {
        return array_merge(parent::share($request), [
            'auth' => [
                'user' => $request->user()?->only('id', 'name', 'email'),
                'can' => [
                    'createInvoice' => $request->user()?->can('create', Invoice::class),
                ],
            ],
        ]);
    }

    This matters in a multi tenant product, where one missed check exposes another customer's data. With one authorization layer, I audit one place. The client hides buttons based on these flags, and the server enforces policies regardless, so a hidden button never acts as a security control.

    Validation and Forms Without a Contract

    Forms showed the biggest gain. A form request validates on the server, and Inertia returns the errors to the component on the next response. The useForm helper tracks errors, processing state, and changed fields without extra code.

    html
    <script setup>
    import { useForm } from '@inertiajs/vue3'
    
    const form = useForm({ customer_id: null, amount: '' })
    
    function submit() {
      form.post(route('invoices.store'))
    }
    </script>

    I write each rule once, in the form request. The client displays whatever errors arrive, so I cannot ship a client rule that disagrees with the server. When a rule changes, I change one file.

    I still add light client checks for fast feedback, such as required fields. I treat them as a convenience and never as validation. The server remains the only authority.

    Testing the Whole Flow

    Testing improved because the page response is assertable in PHP. Inertia ships testing helpers that check the component name and the props a request returns. I test a screen's data contract in the same feature test that covers the route and the authorization.

    php
    use Inertia\Testing\AssertableInertia as Assert;
    
    it('lists invoices for the current tenant', function () {
        $user = User::factory()->create();
        Invoice::factory()->count(3)->for($user->tenant)->create();
    
        $this->actingAs($user)
            ->get(route('invoices.index'))
            ->assertInertia(fn (Assert $page) => $page
                ->component('Invoices/Index')
                ->has('invoices.data', 3)
            );
    });

    This replaced a pair of test suites: API tests in PHP and component tests with mocked responses in JavaScript. The mocked responses had a habit of passing while production failed, because each mock reflected what I believed the API returned. A feature test that asserts real props cannot drift that way.

    I still write component tests for interactive logic, such as table sorting. The data contract no longer needs duplicate coverage. My test suite shrank and caught more regressions.

    Where Inertia Falls Short

    Inertia couples the frontend to Laravel. If the product needs a native mobile app, a public API, or third party integrations, Inertia does not serve those consumers. I keep a small, versioned API for those cases, and I build it after a real consumer exists, not before.

    Become a Sponsor

    Partner with us as a sponsor and help support our mission while connecting your brand with our community. We offer valuable opportunities to showcase your organization and build meaningful partnerships.

    Props also reach the browser in full. Anything passed to the render call appears in the page payload, including fields the interface never displays. I pass API resources instead of models, and I review the page source for leaks the same way I review an API response.

    Large pages need care as well. Heavy props slow every visit, so I use optional props and partial reloads for expensive data. These features work well, but they need deliberate use, and a team that ignores them ships slow pages.

    Conclusion

    I chose Inertia because it removed a layer I did not need and kept the layers I did. Laravel stayed the single source of truth for routing, authentication, authorization, and validation, and the frontend stayed a modern component application.

    The decision depends on the consumers. If only your own frontend calls your backend, a separate API layer adds cost without adding value. When a second consumer appears, I add an API for that consumer, and the Inertia frontend keeps working.

    The best architecture removes the work that does not serve the customer. For my product, that work was an API nobody else used.