Ktor codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the RealWorld spec and API.
Demo
This codebase was created to demonstrate a fully fledged application built with Ktor including CRUD operations, authentication, routing, pagination, and more.
We've gone to great lengths to adhere to the Ktor community style guides & best practices.
For more information on how to this works with other frontends/backends, head over to the RealWorld repo.
Libraries and Tech Specs
To demonstrate Ktor's full capability in building scalable web applications the following Ktor features and libraries were leveraged on;
Ktor Features
- 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.
External Libraries
Database
- 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.
Testing
- 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.
Logging
- Logback: Mature logging library.
Utility
- 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.
Getting started
- WIP