serveHttp
inline fun <T : RpcService> Routing.serveHttp(basePath: String, service: T, env: KsrpcEnvironment<String>, errorCodeToHttpStatus: Map<Int, Int> = DEFAULT_KSRPC_ERROR_CODE_TO_HTTP_STATUS)
Hosts the given service over HTTP on the supplied basePath within a Ktor Routing block.
Samples
val env = ksrpcEnvironment { }
val service = object : GreetingService {
override suspend fun greet(name: String): String = "Hello, $name!"
}
// Embed ksrpc into a Ktor HTTP server.
val server = embeddedServer(Netty, port = 8080) {
routing {
serveHttp("/api", service, env)
}
}
// server.start(wait = true)Content copied to clipboard
fun Routing.serveHttp(basePath: String, serializedService: SerializedService<String>, env: KsrpcEnvironment<String>, errorCodeToHttpStatus: Map<Int, Int> = DEFAULT_KSRPC_ERROR_CODE_TO_HTTP_STATUS)
fun Routing.serveHttp(basePath: String, channel: SerializedChannel<String>, env: KsrpcEnvironment<String>, errorCodeToHttpStatus: Map<Int, Int> = DEFAULT_KSRPC_ERROR_CODE_TO_HTTP_STATUS)