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
@Api
interface SampleApi {
suspend fun getGreeting(name: String, job: String): String
}
client
inline fun <reified API> api(baseUrl: String = serverUrl): API = client.create(baseUrl)
scope.launch {
api<SampleApi>().getGreeting("Hyun", "Programmer")
}
backend
class SampleController : SampleApi {
override suspend fun getGreeting(name: String, job: String): String = "Hello $name($job)"
}
install(SimpleFeature) {
routing {
+SampleController()
}
}