Connect-Kotlin is a slim library for using generated, type-safe, and idiomatic Kotlin clients to communicate with your app's servers using Protocol Buffers (Protobuf). It works with the Connect, gRPC, and gRPC-Web protocols.
Given a simple Protobuf schema, Connect-Kotlin generates idiomatic Kotlin protocol interfaces and client implementations:
ElizaServiceClient.kt
ElizaServiceClientInterface.kt
This code can then be integrated with just a few lines:
class MainActivity : AppCompatActivity() {
private lateinit var elizaServiceClient: ElizaServiceClientInterface
private suspend fun say(sentence: String) {
// Make a unary request to Eliza.
val response = elizaServiceClient.say(SayRequest.newBuilder().setSentence(sentence).build())
val elizaSentence = response.success { success ->
// Get Eliza's reply from the response.
success.message.sentence
}
// Use the elizaSentence in your views.
}
}
That’s it! You no longer need to manually define request/response models, specify the exact path of your request, nor worry about the underlying networking transport for your applications!
Head over to our quick start tutorial to get started. It only takes ~10 minutes to complete a working chat app that uses Connect-Kotlin!
Comprehensive documentation for everything, including interceptors, streaming, and error handling is available on the connectrpc.com website.
Option | Type | Default | Details |
---|---|---|---|
generateCallbackMethods |
Boolean | false |
Generate callback signatures for unary methods. |
generateCoroutineMethods |
Boolean | true |
Generate suspend signatures for unary methods. |
generateBlockingUnaryMethods |
Boolean | false |
Generate blocking signatures for unary methods. |
Example apps are available in /examples
. First, run make generate
to generate
code for the Protobuf plugins.
For the Android example, you can run make installandroid
to build and install
a fully functional Android application using Connect-Kotlin.
Additionally, there are pure Kotlin examples that demonstrate a simple main executable using Connect-Kotlin:
/examples/kotlin-google-java
: A simple Kotlin main
executable using Google's Java Protobuf generator plugin/examples/kotlin-google-javalite
: A simple Kotlin main
executable using Google's Javalite Protobuf generator pluginThe examples demonstrates:
We'd love your help making Connect better!
Extensive instructions for building the library and generator plugins locally,
running tests, and contributing to the repository are available in our
CONTRIBUTING.md
guide. Please check it out
for details.
This project is in beta, and we may make a few changes as we gather feedback from early adopters. Join us on Slack!
Offered under the Apache 2 license.