To demonstrate Ktor's full capability in building scalable web applications the following Ktor features and libraries were leveraged on;
- Routing: Handles incoming requests and provides a simple DSL to capture route mappings.
- Authentication: Handles API authentication.
- Call Logging: Logs application events.
- Status pages: Handles exceptions and errors that occur within a request lifecycle and returns an appropriate response.
- Content Negotiation: Negotiating media types and serializing/deserializing JSON content.
- Exposed: ORM library developed by JetBrains, allowing for model definitions to be written in SQL format, while proving a simple interface and clean DSL.
- HikariCP: Database connection and connection pooling.
- Flyway: Handles database migrations
- Caffeine: High performance in-memory cache based on Guava.
- Jacoco: Mature test coverage and reporting.
- Mockk: Easier mocks, stubs definitions using DSL allowing for easier testing.
- Ktor-tests: Provides Ktor test engine to allow for high fidelity end to end integration tests.
- Test Containers: Provides reusable database instances for testing
- Kotest: Testing framework for rich assertions.
- Logback: Mature logging library.
- Koin - Dependency Injection.
- Gradle with kotlin DSL - a widely adopted build tool, allowing us to write build scripts and code in Kotlin.
- Valiktor - type-safe, powerful and extensible fluent DSL to validate objects in Kotlin.
- Create a .env file, with the format:
- Create a project on firebase or use an existing one to retrieve the service-account.json file.
export DB_HOST=localhost
export DB_PORT=5432
export DB_NAME=notifications
export DB_USER=admin
export DB_PASSWORD=admin
export SERVICE_ACCOUNT_FILE_PATH=path_to_your_firebase_sa.json
- Ensure sure that docker and docker compose are installed on your machine.
- CD to
/docker
and run the following command to initialize the database
cd docker && docker-compose up
- Run the following command to start the ktor sever
source .env && ./gradlew run
- Open a web browser and go to http://0.0.0.0:8080/ and you should see "I'm running!" in the pageš
source .env && ./gradlew clean tests