https://kotlinlang.org logo
#ktor
Title
# ktor
h

Hyun

10/25/2020, 4:31 PM
Hi everyone, I need some advice from Ktor developers. I created a KMP library targeting backend, android, ios - To share api interface between server and client. - Without Http definition like GET, POST, Body, Query etc.. (so, it’s totally looks same with just ‘function’) will this be fine approach? or some advice for this approach? common
Copy code
@Api
interface SampleApi {
    suspend fun getGreeting(name: String, job: String): String
}
client
Copy code
inline fun <reified API> api(baseUrl: String = serverUrl): API = client.create(baseUrl)

scope.launch {
    api<SampleApi>().getGreeting("Hyun", "Programmer")
}
backend
Copy code
class SampleController : SampleApi {
    override suspend fun getGreeting(name: String, job: String): String = "Hello $name($job)"
}

install(SimpleFeature) {
    routing {
        +SampleController()
    }
}
for detail, source code exists on the link below https://github.com/dss99911/kotlin-simple-architecture