r/ktor • • Jun 08 '20

Using ReactiveX (RxKotlin) instead of Kotlin Coroutines

0 Upvotes

I have invested a lot of time in learning ins and outs of ReactiveX programming (RxJava - RxKotlin) and as I find Kotlin Coroutines an interesting component to work with, I rather choose ReactiveX.

Is there any way to use ReactiveX with Ktor and completely get rid of Kotlin Coroutines?

If there is a way It would be great to share some samples or tutorials with me.


r/ktor • • Aug 28 '20

Port 8080 in use but refuses to connect. Need Help.

Thumbnail self.kotlin
0 Upvotes

r/ktor • • Jul 11 '22

Ktor Plugin Cloud Pub/Sub

Thumbnail self.googlecloud
0 Upvotes

r/ktor • • Apr 15 '23

GitHub - kryptokrona/kryptokrona-kotlin-sdk: Kryptokrona SDK in Kotlin for building decentralized private communication and payment systems.

Thumbnail
github.com
0 Upvotes

r/ktor • • Nov 24 '22

Ktor vs Node.js, Django, Go etc..

5 Upvotes

What are the pros and cons of ktor, as compared to servers built using Node.js, Django, Go, and other performant sever side frameworks?

In terms of speed, scalability, number of lines of code to be written etc..

Looking for answers from devs with good knowledge and experience in server side development using multiple frameworks.


r/ktor • • Mar 03 '23

average ktor server downtime during rolling updates

1 Upvotes

I am half way building a backend using ktor and i have recently came to know ktor takes on average of 30sec downtime for creating a new instance example when we use with kubernetes and my backend involved websockets.

From the community could someone pls let me know how much time it's taking for the ktor server to shutdown when u manage via kubernetes and having deployment through rolling updates.

Does anyone using ktor server with kubernetes combination,share ur experience will be great help.


r/ktor • • Apr 29 '23

Ktor project that uses GET request to send another GET request to KPI endpoint

2 Upvotes

I am creating a ktor project to serve a mobile app. The ktor project should receive a GET request from the client and then, once received, it will make an HTTP call to an API to pull some data, and then save this in a database. So I see it as tranforming the initial GET request into another GET request to pull data from an API. I want to check if this a typical pattern to use for a backend (is there anything architecturally wrong here?). If it is a common pattern, does anyone have any examples of projects that do this?


r/ktor • • Oct 05 '25

Why is there no route wrapper in the Resources plugin?

2 Upvotes

I would like to structure my webserver in the example below. My main issue is how I would control route scoped middleware if not foor

@Resource("/groups")
class Groups() {
    @Resource("{group-id)")
    class Id(val parent: Groups = Groups(), val groupid: Long, val date: String?) {
      /* */
    }
}
fun Application.configureGropuRoutes() {
  routing {
    route<Groups> {
      install(IsLoggedIn)
      /* */
      route<Groups.Id> {
        install(IsInGroup)
        get { /* */ }
        post { /* */ }
        /* */
      }
    }
  }
}

Is there a reason why we can't do this? Or is there some other solution I'm missing?


r/ktor • • Aug 12 '26

Konifer - an OSS image management platform built on ktor

3 Upvotes

Hey all, I wanted to share my OSS app called Konifer that I've spent the last 18 months on. You can read more about what it does in the README, but I wanted to highlight the fact that it's written on ktor. It uses JOOQ with R2DBC and communicates with S3 and libvips, a native image processor.

It might be a useful reference application for more advanced ktor use cases. I use several ktor plugins as well. I learned a lot of this the hard way, so I wanted to share my learnings with the community.

Feel free to star to follow along! I'll answer any questions here too.

https://github.com/dmaiken/konifer/


r/ktor • • Feb 15 '23

Ktor Annotations with KSP

3 Upvotes

Hey,

wanted to try out the KSP API and decided to create a simple library that generates code that configures Ktor routes, based on a few annotations.

I'm coming from the Spring world, so of course it looks a little like Spring. You define a "controller" - which can have "Autowired" constructor parameters (anything you define in your Koin modules). And in the controller, you define your routes.

The processor generates a route configuration function that you need to call from your Application.

No reflection is used.

More you can read here: https://github.com/dimitark/ktor-annotations

And if you try it out - please let me know what you think.


r/ktor • • May 12 '25

Is this a valid tech stack for my backend? (Kotlin, Ktor, Exposed, Google Cloud, Firebase Auth, Firebase App Check)

4 Upvotes

I have an existing Android app which I'd like to enhance by implementing a custom backend which is composed of a relational database and user authentication based on Firebase Auth. The business domain model might be something like a recipe app with data such as the sample below. It is not set in stone and just serves as a placeholder for my domain.

{
   "name":"Cheesecake",
   "ingredients":[
      {
         "name":"Banana",
         "amount":150,
         "unit":"grams"
      }
   ]
}

I especially need FTS capabilities so that I can query based on, let's say, the recipe's name. I'm pretty fluent in Kotlin and familiar with SQL.

The tech stack I was thinking about is this:

  • Ktor (backend framework)

  • Exposed (ORM)

  • MySQL (relational database)

Infrastructure:

I'm an experienced Android developer but I'm having practically no backend development experience which is why I don't want to implement authentication myself at this stage.

However I want to secure my backend and since my app integrates Firebase Auth, I'd like to use OpenAPI 2.0 security scheme in API Gateway to secure my backend from unauthorized users.

At the same time I want to secure my backend from unauthorized clients by using Firebase App Check JWT authentication in API Gateway.

What are your thoughts on this? Did I miss something?


r/ktor • • Jul 25 '25

trying to use ktor but getting errors about duplicate classes

4 Upvotes

I started a project in react native and needed to use a websocket server. After looking for a while I couldn't find a solution for this in react-native and decided to write my own module in native kotlin code. I started with this code

package com.nullrequest.foxcam_websocket

import expo.modules.kotlin.modules.Module
import expo.modules.kotlin.modules.ModuleDefinition
import java.net.URL
import io.ktor.server.engine.*
import io.ktor.server.netty.*
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.request.*
import io.ktor.server.routing.*
import io.ktor.server.websocket.*
import kotlinx.coroutines.*

class FoxcamWebsocketModule : Module() {
  private var server: EmbeddedServer<NettyApplicationEngine, NettyApplicationEngine.Configuration>? = null;
  private var serverPort: Int = 8080;
  // Each module class must implement the definition function. The definition consists of components
  // that describes the module's functionality and behavior.
  // See https://docs.expo.dev/modules/module-api for more details about available components.
  override fun definition() = ModuleDefinition {
    // Sets the name of the module that JavaScript code will use to refer to the module. Takes a string as an argument.
    // Can be inferred from module's class name, but it's recommended to set it explicitly for clarity.
    // The module will be accessible from `requireNativeModule('FoxcamWebsocket')` in JavaScript.
    Name("FoxcamWebsocket")
    // Defines event names that the module can send to JavaScript.
    Events("onChange")

    AsyncFunction("startServer") { port: Int ->
      serverPort = port
      startHttpServer()
      "Server started on port $serverPort"
    }

    AsyncFunction("stopServer") {
      stopHttpServer()
      "Server stopped"
    }


    // Enables the module to be used as a native view. Definition components that are accepted as part of
    // the view definition: Prop, Events.
    View(FoxcamWebsocketView::class) {
      // Defines a setter for the `url` prop.
      Prop("url") { view: FoxcamWebsocketView, url: URL ->
        view.webView.loadUrl(url.toString())
      }
      // Defines an event that the view can send to JavaScript.
      Events("onLoad")
    }

    OnDestroy {
      stopHttpServer()
    }
  }

  private fun startHttpServer() {
    if (server!=null) return
    server = embeddedServer(Netty, host="0.0.0.0", port = serverPort) {
      install(WebSockets)

      routing {
        get("/") {
          call.respondText("Foxcam HTTP Server is running on port $serverPort")
        }

        get("/hello") {
          val name = call.request.queryParameters["name"] ?: "Guest"
          call.respondText("Hello, $name!")
        }
      }
    }.start(wait = false)
  }


  private fun stopHttpServer() {
    server?.stop(gracePeriodMillis = 1000, timeoutMillis = 2000)
    server = null
  }
}

(if this is a horrible way of doing things please feel free to yell at me i've never used kotlin before). I tried building this and got errors about various classes from io.netty having duplicate classes, an example of the error is

Duplicate class io.netty.bootstrap.AbstractBootstrap found in modules netty-all-4.1.48.Final.jar -> netty-all-4.1.48.Final (io.netty:netty-all:4.1.48.Final) and netty-transport-4.2.2.Final.jar -> netty-transport-4.2.2.Final (io.netty:netty-transport:4.2.2.Final)
Duplicate class io.netty.bootstrap.AbstractBootstrap$1 found in modules netty-all-4.1.48.Final.jar -> netty-all-4.1.48.Final (io.netty:netty-all:4.1.48.Final) and netty-transport-4.2.2.Final.jar -> netty-transport-4.2.2.Final (io.netty:netty-transport:4.2.2.Final)

I don't know enough about kotlin or gradle to fix these errors so pointers would be appricated


r/ktor • • Jul 24 '25

Seamless Android File Sharing Using Ktor Client/Server in Kotlin

4 Upvotes

Hi everyone 👋,

I recently worked on a Kotlin-based Android project that allows offline file transfer between two devices using a Ktor client-server setup and QR code-based pairing. Thought it would be relevant to share it here for feedback and to showcase Kotlin’s versatility—even for peer-to-peer communication use cases.

⚙️ How It Works

Both users install the same Kotlin Android app.

User A (Sender) selects photos/videos → Long press triggers QR generation with connection metadata.

User B (Receiver) scans the QR code → App opens camera → Connects to sender via embedded Ktor server → Starts secure file download.

Entire exchange runs offline on a local network (e.g., hotspot or Wi-Fi Direct).

💡 Why Kotlin + Ktor?

I wanted a clean, maintainable, coroutine-backed HTTP layer, and Ktor's embedded Netty server worked great for that. The entire logic is built in pure Kotlin, from the file provider logic to coroutine-based byte streaming.

📖 Full Write-Up & Demo

👉 Medium Post – Seamless Data Exchange Between Android Apps Using Ktor

Includes:

Architecture overview

GIF demo of real usage

Code structure using Kotlin coroutines

File server/client logic using Ktor

QR generation/scanning with ZXing

🧠 Looking for Suggestions

Would love your thoughts on:

Optimizing Ktor server lifecycle in Android

Handling large files efficiently with Kotlin coroutines

Making the architecture more modular (KMM friendly maybe?)

This is my first public Kotlin project post—any encouragement, critique, or improvement ideas are welcome 🙏


r/ktor • • May 04 '25

Best way to implement admin-only routes

5 Upvotes

I want to add routes only admins can access, to build an admin web interface. I thought the easiest way would be to have routes that only allow requests from localhost, maybe even on a different port than the public REST API, so only admins using a SSH tunnel for example could access them.

What are other ways to implement admin-only routes? Maybe using one of the authentication methods provided by Ktor?


r/ktor • • Apr 05 '25

Is WebSocket send method thread-safe

2 Upvotes

I am working with a new project, with server written on kotlin + ktor. Following this tutorial, I see that send is the simplest way to send text to clients.

But due to my lower business logic, the response may come from another thread/coroutine (actually it's from other machines with real-time bidirectional connections, and I cannot control of which thread will call send), I should be aware of thread-safety. Is it ok to write code like this, or I must use some form of lock to write only 1 frame at a time, such as Mutex?

withContext(Dispatchers.IO) {
    launch {
        send(Frame.Text(text1))
    }
    launch {
        send(Frame.Text(text2))
    }
}

r/ktor • • Sep 16 '24

new to ktor

4 Upvotes

Hi everyone,

I am new to ktor and i want to build Restful api from it.

Can anyone just tell me what should be my approach and from where i can learn the basics to build custom api for the native android app.

Thanks..


r/ktor • • Dec 19 '25

Database migrations with Exposed

Thumbnail kborowy.com
3 Upvotes

r/ktor • • Jun 02 '25

Migration to Ktor tests 3.x - TestApplicationEngine

2 Upvotes

Hi
I'm migrating my tests to Ktor 3.x from 2. I have issues with migrating the TestApplicationEngine. I can't find any documentation about how should I create this in Ktor 3. Is there a way to use TestApplicationEngine or do I have to migrate to testApplication?


r/ktor • • Jan 09 '26

Better Logging for Ktor with MDC

Thumbnail medium.com
2 Upvotes

r/ktor • • Feb 15 '23

Ktor Server Discovery and Client Finding

2 Upvotes

Is it possible to make the server discoverable so that a ktor client can find it?

And are there any libraries to make this easy to do?

Edit: Added another question.


r/ktor • • Aug 02 '23

Support of RabbitMQ, Redis, gRPC in ktor

4 Upvotes

I consider to try ktor for my next microservice. But I've found out that ktor doesn't provide out-of-the-box support for such common things like Kafka, RabbitMQ, gRPC, Redis etc.

What is the philosophy and reasons behind this? Does it mean that the only area for ktor are lightweight servers with very basic functionality?


r/ktor • • Jul 02 '23

How do you use partial with Mustache?

1 Upvotes

Hi, is there a guide somewhere on how to use partials with Mustache on Ktor? The only guide I found is this one https://ktor.io/docs/mustache.html and doesn't say much. Also Google wasn't much helpful.


r/ktor • • Nov 23 '23

Hello everyone. I'm planning to get into ktor. Can you suggest any good resources. Thanks

1 Upvotes

r/ktor • • Apr 04 '23

Real world example of a Kotlin/Ktor project

3 Upvotes

Hi fellow Ktor developers,

I put together a project which I use technologies such as: Ktor, Ktorm, Liquibase, PostgreSQL, DBCP2, Docker, Ansible and much more.

Just wanted to share this if someone would find it useful to see a real world use case using these technologies for inspiration or perhaps better for myself, some feedback in the forms of PRs if you want to contribute! :)

Link to GitHub project: https://github.com/kryptokrona/kryptokrona-api


r/ktor • • Jul 27 '23

Ktor in vscode

3 Upvotes

I want to use kotlin and ktor in vscode because I really don't like needing to upgrade to the intellij IDEA ultimate for being able to access the ktor plugin. (also doesn't like intellij)

So does anyone know good plugin for eather kotlin or/and ktor