Vue JS + Spring Boot REST API Tutorial

In this tutorial, we will learn how to build a simple Full Stack application using Spring boot as backend and Vue JS as frontend.

Vue JS is a progressive framework for building user interfaces (UI) on the front end.

Spring Boot is a very popular Java framework for building RESTful web services and microservices.

In this tutorial, we will use the Axios HTTP library to make HTTP Get REST API call.


Tools and technologies used

  • Spring Boot 3
  • Spring MVC
  • Spring Data JPA (Hibernate)
  • Eclipse STS
  • H2 Database
  • Vue 3
  • Axios
  • Bootstrap 4
  • VS Code

What we will build?

We will build two projects:
  1. springboot-backend - Develop and expose REST APIs
  2. vue-frontend - Consume REST APIs

1. Develop Spring boot application - Backend

Let's begin with creating a Spring boot application and build a simple REST API.

1. Create a Spring Boot Application

There are many ways to create a Spring Boot application. You can refer to the below articles to create a Spring Boot application.

2. Add maven dependencies

Here is a complete pom.xml file for your reference:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="" xmlns:xsi=""
		<relativePath/> <!-- lookup parent from repository -->
	<description>Spring Boot backend application</description>




3. Create JPA Entity -

Let's create a new package called entity inside net.javaguides.springboot package and then create the Employee class inside the entity package with the following contents -
package net.javaguides.springboot.entity;

import lombok.*;

import jakarta.persistence.*;

@Table(name = "employees")
public class Employee {

    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private long id;

    @Column(name = "first_name", nullable = false)
    private String firstName;

    @Column(name = "last_name")
    private String lastName;
    private String email;


4. Create Spring Data JPA Repository -

Now, we gonna create a Spring Data JPA repository to talk with the H2 database. Let's create a new package called repository inside net.javaguides.springboot package and then create the following EmployeeRepository interface inside the repository package:
package net.javaguides.springboot.repository;

import net.javaguides.springboot.entity.Employee;

public interface EmployeeRepository extends JpaRepository<Employee, Long> {


5. Spring Controller with REST API - /api/employees

Let's create a new package called controller inside net.javaguides.springboot package and then create the following EmployeeController class inside the controller package with the following contents -
package net.javaguides.springboot.controller;

import net.javaguides.springboot.entity.Employee;
import net.javaguides.springboot.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

public class EmployeeController {

    private EmployeeRepository employeeRepository;

    public List<Employee> fetchEmployees(){
        return employeeRepository.findAll();
Note that we have added the below code to avoid CORS issues:
@CrossOrigin(origins = "http://localhost:3000")

6. Run Spring Boot Application and Test Rest API

Let's insert a few records in the employees table while application startup.
package net.javaguides.springboot;

import net.javaguides.springboot.entity.Employee;
import net.javaguides.springboot.repository.EmployeeRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

public class SpringbootBackendApplication implements CommandLineRunner {

	public static void main(String[] args) {, args);

	private EmployeeRepository employeeRepository;

	public void run(String... args) throws Exception {

		Employee employee1 = Employee.builder()
				.email("[email protected]")

		Employee employee2 = Employee.builder()
				.email("[email protected]")

		Employee employee3 = Employee.builder()
				.email("[email protected]")
Let's run this spring boot application from IDE -> Right-click -> Run As -> Java Application:

Hit this "http://localhost:8080/api/employees" link in a browser will popular list of employees as JSON:

      "email":"[email protected]"
      "email":"[email protected]"
      "email":"[email protected]"

Build Vue JS Frontend Application

Let's go ahead and create a Vue application to consume /api/employees REST API.
We will use Vue 3 and Axios HTTP library to make a REST API call in the Vue application. We will use VS Code IDE to build the Vue application.

1. Vue JS Project Setup

To install and use the Vue CLI as well as run the Vue application server, you'll need the Node.js JavaScript runtime and npm (the Node.js package manager) installed. npm is included with Node.js which you can install from Node.js downloads.

To test that you have Node.js and npm correctly installed on your machine, you can type

node --version 
npm --version

To install the vue/cli, in a terminal or command prompt type the below command(Note: open cmd using an administrator in Windows. For Mac/Linux, use the sudo before below command to give permission):

npm install -g @vue/cli

This may take a few minutes to install. You can now create a new Vue.js application by typing:

vue create vue-frontend

where vue-frontend is the name of the folder for your application.

Let's quickly run our Vue application by navigating to the new folder and typing npm run serve to start the webserver and open the application in a browser:

cd vue-frontend
npm run serve

2. Install Vetur extension in VS Code

Let's install the Vetur extension in VS code, this extension supplies Vue.js language features (syntax highlighting, IntelliSense, snippets, formatting) to VS Code.

3. Add Bootstrap to Vue App

Go to terminal and navigate to your project's folder, and run the following command:
npm install bootstrap —save
npm install --save @popperjs/core
After installing the bootstrap package, you will need to import it into your Vue app entry file.
import Vue from 'vue'
import App from './App.vue'
import 'bootstrap'
import 'bootstrap/dist/css/bootstrap.min.css'

Vue.config.productionTip = false

new Vue({
  render: h => h(App),

4. Vue Service Class - REST API Call

For our API calls, we will be using Axios. Below is the npm command to install Axios.
npm add axios
Let's create a services folder within an src folder. Within the services folder, create an EmployeeServce.js class with the following code to make our HTTP REST call via Axios. 
import axios from 'axios';

const EMPLOYEE_API_BASE_URL = 'http://localhost:8080/api/employees';

class EmployeeService{

        return axios.get(EMPLOYEE_API_BASE_URL);

export default new EmployeeService();
Note that our backend Employee endpoint is available at http://localhost:8080/api/employees.
Make sure that you create an object of EmployeeService class export it as:
export default new EmployeeService();

5. Create Vue Component - src/components/Employees.vue

Let's create a components folder within the src folder and create an Employees.vue file with the following code to it.
    <div class = "container">
            <h1 class = "text-center"> Employees List</h1>

            <table class = "table table-striped">
                        <th> Employee Id</th>
                        <th> Employee First Name</th>
                        <th> Employee Last</th>
                        <th> Employee Email</th>

                    <tr v-for="employee in employees" v-bind:key="">
                        <td> {{ }}</td>
                        <td> {{employee.firstName }}</td>
                        <td> {{employee.lastName}}</td>    
                        <td> {{}}</td>


import EmployeeService from '../services/EmployeeService';

export default {
    name: 'Employees',
        return {
            employees: []
    methods: {
            EmployeeService.getEmployees().then((response) => {
                this.employees =;   
    created() {

Let's understand the above code step by step:
One of the first things you would need to understand about Vue is the concept of the component. Vue component is consists of template, script, and style.
  • template is nothing but the HTML template with Vue directives
  • script is javascript code to write for the Vue module
  • style is CSS for the Vue module
created() - Vue defines a component lifecycle. created will be called as soon as the component is mounted. We are calling getEmployees() as soon as a component is mounted:
created() {
methods: { getEmployees() {}} - Any method in a Vue component should be under methods. 
methods: {
            EmployeeService.getEmployees().then((response) => {
                this.employees =;   
EmployeeService.getEmployees().then - This would make the call to the REST API. You can define how to process the response in the then method:
            EmployeeService.getEmployees().then((response) => {
                this.employees =;   

6. App Component - src/App.vue

Let’s update the App.vue to display the Employees component.

  <div id="app">
    <Employees />

import Employees from './components/Employees.vue'

export default {
  name: 'App',
  components: {

#app {
  font-family: Avenir, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-align: center;
  color: #2c3e50;
  margin-top: 60px;

7. Run Vue Application

Open a terminal and move to the project folder and type the below command to run the Vue application:
npm run serve
Runs the app in development mode. Open http://localhost:8081 to view it in the browser.


In this tutorial, we have learned how to build a simple Full Stack application using Spring boot as backend and Vue JS as frontend.