RPC Clients

Edit pageLast modified: 22 November 2024

For each declared service, kotlinx.rpc will generate an actual client implementation that can be used to send requests to a server. You must not use generated code directly. Instead, you should use the APIs that will provide you with the instance of your interface. This generated instance is commonly called a stub in RPC.

To be able to obtain an instance of your service, you need to have an RpcClient. You can call the withService() method on your client:

Now you have your client instance that is able to send RPC requests to your server. RpcClient can have multiple services that communicate through it. Conceptually, RpcClient is an abstraction of a client, that is able to convent service requests (represented by the RpcCall class) into actual network requests.

You can provide your own implementations of the RpcClient. But kotlinx.rpc already provides one out-of-the-box solution that uses in-house RPC protocol (called kRPC), and we are working on supporting more protocols (with priority on gRPC).