Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

TheDude's avatar

Inertia or API - reasons for each one?

I've been using Inertia with Vue and enjoy it, but I was thinking what influences you to choose API, what are the practical differences? What are the pros and cons of each?

0 likes
12 replies
LaryAI's avatar
Level 58

The decision to use Inertia or an API depends on the specific needs of your project. Here are some factors to consider:

Inertia:

  • If you are building a traditional server-rendered application and want to add some interactivity with Vue, Inertia can be a good choice.
  • Inertia allows you to use Laravel's routing and controller system, which can make it easier to build and maintain your application.
  • Inertia can be faster to develop with, since you don't need to build a separate API layer.

API:

  • If you are building a single-page application (SPA) or a mobile app, an API may be a better choice.
  • An API allows you to decouple your front-end and back-end, which can make it easier to scale and maintain your application.
  • An API can be more flexible, since it allows you to use any front-end framework or technology.

Ultimately, the choice between Inertia and an API depends on your specific needs and preferences. If you are already comfortable with Inertia and it meets your needs, there may be no need to switch to an API. However, if you are building a more complex application or need more flexibility, an API may be a better choice.

Example code for using Inertia with Laravel and Vue:

// In a Laravel controller
public function index()
{
    $users = User::all();
    return inertia('Users/Index', ['users' => $users]);
}

// In a Vue component
<template>
  <div>
    <h1>Users</h1>
    <ul>
      <li v-for="user in $page.users" :key="user.id">
        {{ user.name }}
      </li>
    </ul>
  </div>
</template>

<script>
import { usePage } from '@inertiajs/inertia-vue'

export default {
  setup() {
    const { users } = usePage().props
    return { users }
  }
}
</script>

Example code for building an API with Laravel:

// In a Laravel controller
public function index()
{
    $users = User::all();
    return response()->json(['users' => $users]);
}

// In a Vue component
<template>
  <div>
    <h1>Users</h1>
    <ul>
      <li v-for="user in users" :key="user.id">
        {{ user.name }}
      </li>
    </ul>
  </div>
</template>

<script>
export default {
  data() {
    return {
      users: []
    }
  },
  mounted() {
    axios.get('/api/users')
      .then(response => {
        this.users = response.data.users
      })
  }
}
</script>
lscura's avatar

Did you decide what to choose here? I am about to build my personal website in Laravel and Vue but I am unsure on what to choose. It will be a typical blog with posts, tags, projects, etc.

JussiMannisto's avatar

@lscura Use Inertia.

Decoupling the front end from the back end makes things more complicated. I'd only do that for a good reason, and it doesn't sound like you have one.

martinbean's avatar

Did you decide what to choose here? I am about to build my personal website in Laravel and Vue but I am unsure on what to choose. It will be a typical blog with posts, tags, projects, etc.

@lscura Why do you need an API or Inertia for any of those features? Just build your app, with controllers and Blade views.

It amazes me how complicated people make simple projects.

JussiMannisto's avatar

@martinbean Vue isn't that complicated. And it's good to know it if you're looking for a job as a junior. I don't see this as a bad idea.

1 like
martinbean's avatar

@JussiMannisto I never said Vue was complicated. But it’s completely overkill for displaying a blog post stored in a database table. Displaying content from a database doesn’t require a JavaScript library like Vue, at all.

1 like
JussiMannisto's avatar

@martinbean Sure, if you just want it to work. But I just guessed based on the description that it's a learning / demo project. Vue fits well there. And it's a bit nicer UX-wise.

lscura's avatar

@martinbean Based on your criteria, why even bother using Laravel then? Just static HTML and hardcode the posts haha. Just kidding, forgot to mention I am more familiar with frontend (Vue), and even though I can make it only with blade files, I want to integrate Vue and much rather integrate and practice on a simple than a complicated project! Thanks for your answer.

gych's avatar

@lscura Do you already have experience with Laravel and Blade ?

gych's avatar

@lscura Then its perfectly fine to use Laravel with Vue and Inertia for this personal project. It won't be that hard since you already know Vue and its a good learning experience to learn Inertia.

1 like

Please or to participate in this conversation.