Ktor is a web application framework written in Kotlin that utilizes Coroutines to provide the fully asynchronous, non-blocking behavior. Shows usage of ktor to create a simple API to store simple todo list.
Building the project
./gradlew clean && ./gradlew build
Compiling the project and generating a docker image
./gradlew clean && ./gradlew build && docker build --no-cache -t crisun/ktor-koin-sample-app .
Compiling the project and generating a docker image with docker-compose
./gradlew clean && ./gradlew build && docker-compose build
Using docker-compose:
docker-compose up
Using docker:
docker run --rm -it -p 8080:8080 crisun/ktor-koin-sample-app
Running manually:
java -jar ktor-koin-sample-app-1.0.0-all.jar
Start the application and call the operations:
Login to obtain jwt token:
curl -i -XPOST -H "Content-type: application/json" "http://localhost:8080/user/login" -d '{"username":"crisun","password":"r4e3w2q1"}'
List all tasks:
curl -i -H "Authorization: Bearer $TOKEN" "http://localhost:8080/todos"
Query a task:
curl -i -H "Authorization: Bearer $TOKEN" "http://localhost:8080/todo/1"
Insert task:
curl -i -XPOST -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" "http://localhost:8080/todo" -d '{"title":"Task 1","description":"Do the homework"}'
Update task:
curl -i -XPUT -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" "http://localhost:8080/todo/1" -d '{"title":"Task 1","description":"Do the homework and clean the house"}'
Delete task:
curl -i -XDELETE -H "Authorization: Bearer $TOKEN" -H "Content-Type: application/json" "http://localhost:8080/todo/1"
Health check:
curl -i "http://localhost:8080/health"
Koin: https://insert-koin.io
Flywaydb: https://flywaydb.org
Logback: http://logback.qos.ch
Spring Jdbc: https://spring.io
H2 Database: https://www.h2database.com
HikariCP: https://github.com/brettwooldridge/HikariCP
Kotlin Logging: https://github.com/MicroUtils/kotlin-logging
Ktor flyway feature: https://github.com/viartemev/ktor-flyway-feature
Ktor JWT feature: https://ktor.io/servers/features/authentication/jwt.html