In this example repository, you will be able to see KTOR based backend application working with a couple of techniques ;
- KTOR
Kotlin based web framework.
- JWT
- Exposed
ORM Framework for Kotlin.
- PostgreSQL
- Flyway
Migration tool for database
With docker compose, the application will be exposed on 9090 port with 5432 database connections.
docker compose build
docker compose up
Note: If you want to change ports of the configuration, please check Dockerfile and docker-compose.yml
In application.conf you will see some environment variables for test purposes. If you want to run this app in another circumstances, you should change these variables either in application.conf or Dockerfile.
- PORT
If you change this config, your application will be working on that port.
- JWT_SECRET
Secret for JWT creation.
- DB_PASSWORD
database password
- DB_CONNECTION
database connection string
- DB_USERNAME
database username
In the example below, you see Json Web Token Authentication between client and server.
sequenceDiagram
Client ->> Resource: Hello Resource, I want this data from you
Resource ->> Client: I don't know who you are(401)
Client ->> JWT Server: Hello, here is my username&password for data
JWT Server ->> Client: Okey, I know you. Here is your token(access_token)
Client ->> Resource: Here I am again with Bearer access_token
Resource ->> Client: Okey, I know you. This is your data(200)
Note: The Login API is working on current KTOR 2.0.1 version and working with dockerized PostgreSQL in development environment. If you want to use, please change configuration file inside resources file.