A Spring Boot RESTful API modelled after the http://predic8.de API example, executing the standard set of CRUD operations on a set of data around the concept of a fruit shop.
The project allows for connection to either an H2 database (default), or a MySQL database. To change these, comment/uncomment the relevant application properties yml files.
To generate the MySQL database, tables and users, follow the SQL queries inside the file src/main/scripts/configure-mysql.sql
. For the H2 database, initial data is read in via the Bootstrap
class.
Unit tests are written with JUnit 5 and continuous integration testing is done through CircleCi 2.0. JacCoCo is used to provide test coverage information for the unit tests.
- Java 11
- Spring Boot 2.2.1.RELEASE
- Maven 3.6.2
- H2/MySQL 8.0.18
- JUnit 5
-
Fork or clone the project.
-
Start the project server by running the command
mvn spring-boot:run
. -
The API can be called with any of the following cURL CRUD-based requests (in either JSON or XML formats):
-
GET/READ:
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/api/v1/categories/'
curl -X GET --header 'Accept: application/xml' 'http://localhost:8080/api/v1/categories/'
curl -X GET --header 'Accept: application/json' 'http://localhost:8080/api/v1/vendors/'
curl -X GET --header 'Accept: application/xml' 'http://localhost:8080/api/v1/vendors/'
-
CREATE/ADD:
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"name": "test"}' 'http://localhost:8080/api/v1/categories/'
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{"name": "test"}' ''http://localhost:8080/api/v1/vendors/'
-
-
Check code coverage with the command
mvn test jacoco:report
.
API documentation is provided by means of Swagger2, which can be opened in the browser with the following urls: