How to connect to external api on ktor server

Viewed 212

I have a ktor server that exposes an API to my android client. It has its own database, some signup structure, and all the standard stuff. But now, a part of my database is getting filled with data from an 3rd party database, which I can only reach via it's own API. That means my server is a client on itself. I know this might not be the best structure, but that's how it is right now. So I need an HTTPClient for my server I think. For that I need to use an engine, but should I use the same engine as the one that I use for my server? How do I set it up in my DI, Koin, so that my services have access to the HTTPClient (factory or single) Right now I set up the server part like this:

fun main(args: Array<String>): Unit = io.ktor.server.netty.EngineMain.main(args)

@Suppress("unused") // Referenced in application.conf
@kotlin.jvm.JvmOverloads
fun Application.module(testing: Boolean = false) {
    install(ContentNegotiation) {
        serialization()
    }
    install(Koin) {
        modules(
            KoinModules.exposedModule,
            KoinModules.repositoryModule
        )
    }

    val userRepository by inject<UserRepository>()

    routing {
    ...

application.conf

ktor {
    deployment {
        port = 8080
        port = ${?PORT}
    }
    application {
        modules = [ com.kvw.letsgo.server.ApplicationKt.module ]
    }
}

Should I change my main(), lose application.conf and code it by hand so that I use the same engine?

0 Answers
Related