This post walks you through the process of creating a RESTful API Example with Spring Boot, Integration Test with MockMVC, UI Integration with VueJS

What you'll need

  • JDK 1.8+
  • Maven 3+

Stack

  • Spring Boot
  • MockMVC
  • VueJS

Project structure

├── src
│   ├── main
│   │   ├── java
│   │   │   └── com
│   │   │       └── hellokoding
│   │   │           └── restfulapi
│   │   │               ├── api
│   │   │               │   └── StockAPI.java
│   │   │               ├── model
│   │   │               │   └── Stock.java
│   │   │               ├── service
│   │   │               │   └── StockService.java
│   │   │               ├── web
│   │   │               │   └── StockController.java
│   │   │               ├── Application.java
│   │   │               └── StockData.java
│   │   └── resources
│   │       ├── static
│   │       │   ├── stocklist.css
│   │       │   └── stocklist.js
│   │       ├── templates
│   │       │   └── stocklist.html
│   │       └── application.properties
│   └── test
│       └── java
│           └── com
│               └── hellokoding
│                   └── restfulapi
│                       └── StockAPITest.java
└── pom.xml

Project dependencies


Domain objects


Data


Service


RESTful APIs


Web Controller


UI Integration with VueJS



Integration Test with MockMVC


Run the application


  • Type mvn clean spring-boot:run on terminal at the project root directory to run
  • Access to http://localhost:8080

Test the application

Get all stocks

curl http://localhost:8080/api/v1/stocks

Get stock id 1

curl http://localhost:8080/api/v1/stocks/1

Update price of stock 1

curl -X PUT -d 'currentPrice=123' http://localhost:8080/api/v1/stocks/1

Create a new stock

curl -H "Content-Type: application/json" -X POST -d '{"name":"S11","currentPrice":"11"}' http://localhost:8080/api/v1/stocks

Source code

[email protected]:hellokoding/restfulapi-springboot-mockmvc-vuejs.git

https://github.com/hellokoding/restfulapi-springboot-mockmvc-vuejs

VueJS Grid Component Example