Water Level Monitor is an ReST Full Api for logging of water levels. It collects water level measurement for presenting it later on a website. The user is able to create different rivers/lakes and related locations. Those locations collect the actual measurements and send them to the server. (For this demo we will skipp the collecting part and will fill the server with demo data)
- Alexander Kauer
- Fabian Schedler
To create your own Ktor-Project have a look on ktor.io and Ktor-docs.
- IDE with Kotlin support (e.g. IntelliJ IDEA)
- JDK >= 11 installed (or bundled with IDE)
- Local MongoDB running on default port (27017) and accessible without credentials (or change the dbUri in the configs)
- Clone the repository
- Do a gradle sync
- Start the server
- With the IntelliJ IDEA you can use the preconfigured
Server
run configuration - You can also start the server with the command
./gradlew run
- With the IntelliJ IDEA you can use the preconfigured
- Navigate to http://localhost:8080/api - You should
see
Running WaterLevelMonitor-API! ( ͡° ͜ʖ ͡°)
The project comes preconfigured for DEVELOPMENT. You can change the default configuration with environment variables. For available options have a look at .env.sample and Config.kt
!!!ATTENTION!!!
The default configurations are not for use in production environments! Provide custom config for your production environment and also make sure to set theENVIRONMENT
variable toproduction
.
We will use Kotlin as language and Ktor as server framework. Furthermore, we will use MongoDB for storing all our data.
You can find a short introduction into the technology in the provided slides.
- Kotlin
- Ktor
- Ktor Auth
- Ktor ContentNegotiation with Kotlinx Serialization
- MongoDB with Katerbase driver
- JSON as content format
- JWT based authentication
- ReST Full API
- Mongo Database
- automated tests with Gitlab CI/CD
For Ktor at current state it is not so simple to automatically generate OpenAPI documentation from code directly. This is also due to the frameworks flexibility which does not force you to use a specific design, structure or architecture. Nevertheless, we created a Postman collection which can be imported in Postman. From there it can be used to test or play with some endpoints and also to view the documentation.