Skip to content

jonas-tm/ktor-native-server-example

Repository files navigation

Ktor Native Server Example

This repository contains a sample Ktor 2.0 server program that runs only with Kotlin/Native.

The server includes the following functionalities:

  • SQLDelight Postgrs connection
  • Sample REST API with KotlinX JSON Serialization
  • Global error handling middleware
  • Sample Application Plugin (Middleware) for request logging

The ktor server is running with CIO Engine (Coroutine-based I/O) which is the only on supported by Kotlin/Native (Netty, Jetty and Tomcat are JVM based). More general information can be found here: https://ktor.io/docs/native-server.html

Supported Platforms

  • Linux (x64, Arm64)
  • MacOS (x64, Arm64)

How to run

  1. Start Postgres instance docker compose up
  2. Debug ./gradlew runDebugExecutable
  3. Visit http://localhost:8080/api/v1/news and see NewsRoutes.kt for further use of the API

Tests: ./gradlew allTests

Known Problems

  • Problems with tests in IntelliJ: Cannot access class 'io.ktor...'. Check your module classpath for missing or conflicting dependencies
    • Open bug can be overcome by adding following to gradle.properties
      • kotlin.mpp.hierarchicalStructureSupport=false

Planned Features

About

Kotlin/Native Ktor Server with PostgreSQL

Topics

Resources

Stars

18 stars

Watchers

1 watching

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages