The project consists of creating, in the REST standard, an API sample to make travel requests with the resources that allow the following functionalities:
- CRUD (Create, Read, Update, Delete) for drivers
- CRUD (Create, Read, Update, Delete) for passengers
- Travel request creation
- Driver find available travel requests
- Driver accept travel request
- Driver refuse travel request
This is a test project to understand the work joining Kotlin and Spring. The purpose of this API is to store driver and passenger data, making it possible to query available trips and providing endpoints to accept or reject a travel. This project also proposes to practice test pyramid concepts and understand how important it is for the life cycle of a software project.
- Travel requests
- CRUD
- Kotlin
- Spring
- Tests (unit, integration, components/end-to-end)
- Containers
The objective was to determine a simple architectural model, following the pattern: controller -> service -> repository.
The structure follows the following definition:
The controller accesses the service generating the domain objects, the service accesses the repository generating the entity objects.
Some good practices:
- No layer access Controller
- Service/models can only be accessed by Controller or another Service
- Repository/entities can only be accessed by Service
To make it easier, let's see a perspective of the feature of creating a passenger:
The project is documented by springdoc-openapi-ui, so just access the following address:
http://localhost:8080/travels-api/swagger-ui
- IntelliJ IDEA - The IDE used
- Java 8 - Execution platform
- Spring Boot - 2.6.2 - Spring Boot makes it easy to create stand-alone, production-grade Spring based Applications that you can "just run"
- PostgreSQL - The database used
- Kotlin - Language
- JUnit - Unit and integration tests
- SpringMockK - Support for Spring Boot integration tests written in Kotlin using MockK instead of Mockito
- Docker - Operating system-level virtualization.
- H2 Database - In memory database for integration tests
- Mockito - Tasty mocking framework for unit tests
- REST Assured - Testing and validating REST services
- Spring Doc Open API - Library helps to automate the generation of API documentation using spring boot projects
To get a local copy up and running follow these simple steps.
This project requires Java 8 or higher and use an IDE of your choice that supports Maven.
Clone the repo
git clone https://github.com/ezequieljuliano/kotlin-spring-rest-api-sample.git
Open the project in your preferred IDE and run the main class TravelsApplication and use Postman to call the resources.
Execute the command below in the terminal to generate the application's artifact and build the application's docker image:
mvn clean package dockerfile:build
Now execute:
docker-compose up
Run the unit tests and check that everything is fine. Unit tests, integration tests and components/end-to-end tests were implemented.
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature
) - Commit your Changes (
git commit -m 'Add some AmazingFeature'
) - Push to the Branch (
git push origin feature/AmazingFeature
) - Open a Pull Request
To contact us use the options:
- E-mail : ezequieljuliano@gmail.com
- Twitter : @ezequieljuliano
- Linkedin: ezequiel-juliano-müller