DEV Community

Michael Z
Michael Z

Posted on • Originally published at michaelzanggl.com

3 2

Build Adonis/Vue apps without an API

In a previous post I created a prototype of seamless integration between frontend and backend.

To save you from reading the article, here's a gist:

No more fetch requests to the backend, no more setting up API routes, no need for controllers. Leaving you with what is essentially just calling a function (referred to as an action).

Under the hood, it creates the API routes automatically and turns backend imports on the frontend into network requests.

This time I've taken the same approach and applied it to something more realistic. An app that uses Adonis.js on the backend and Vue.js on the frontend.

How it looks like

Here is the GitHub of the little app. It contains a couple of actions like getting all users, creating users, and logging in.

To keep this example simple, let's just see how we can get the list of all users.

Backend (extracted from Actions/user.js)

const User = use('App/Models/User')

exports.getAllUsers = async function() {
  return User.all()
}
Enter fullscreen mode Exit fullscreen mode

Frontend (extracted from App.vue)

<template>
  <ul>
    <li v-for="user in users" :key="user.id">
      [{{ user.id }}] {{ user.email }}
    </li>
  </ul>
</template>

<script>
import { getAllUsers } from '../../api/app/Actions/user'

export default {
    data() {
        return { users: [] }
    },
    async mounted() {
        this.users = await getAllUsers()
    }
}
</script>
Enter fullscreen mode Exit fullscreen mode

Seeeeamless ;)

Changes to the previous prototype

Mainly there's a new seamlesslyrc.json file that holds everything together. The backend will write all generated routes to this file and the frontend will then consume it.

Having this file comes with a lot of benefits over the previous prototype:

  • No need for language/framework parsing
  • single source of truth for the whole API generation
  • Can be used to look up the API
  • Can be used to store more things in the future like the endpoint prefix (currently always /api)
  • using other HTTP methods than just POST is a lot easier.

The loader and API generator is under a new package called seamlessly.

And you can find the integration for the above example here:


There are still some things that require some more thought, but I guess for the next test, I will try to use a non-JS language as the backend. Laravel 🤔🤔🤔

Top comments (0)

Image of AssemblyAI

Automatic Speech Recognition with AssemblyAI

Experience near-human accuracy, low-latency performance, and advanced Speech AI capabilities with AssemblyAI's Speech-to-Text API. Sign up today and get $50 in API credit. No credit card required.

Try the API

👋 Kindness is contagious

Dive into an ocean of knowledge with this thought-provoking post, revered deeply within the supportive DEV Community. Developers of all levels are welcome to join and enhance our collective intelligence.

Saying a simple "thank you" can brighten someone's day. Share your gratitude in the comments below!

On DEV, sharing ideas eases our path and fortifies our community connections. Found this helpful? Sending a quick thanks to the author can be profoundly valued.

Okay