A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://github.com/connectrpc/connect-kotlin below:

connectrpc/connect-kotlin: The Kotlin implementation of Connect: Protobuf RPC that works.

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:

Click to expand ElizaServiceClient.kt
public class ElizaServiceClient(
    private val client: ProtocolClientInterface
) : ElizaServiceClientInterface {
    public override suspend fun say(request: SayRequest, headers: Headers):
        ResponseMessage<SayResponse> = client.unary(
        request,
        headers,
        MethodSpec(
            "connectrpc.eliza.v1.ElizaService/Say",
            com.connectrpc.eliza.v1.SayRequest::class,
            com.connectrpc.eliza.v1.SayResponse::class
        )
    )

    public override suspend fun converse(headers: Headers):
        BidirectionalStreamInterface<ConverseRequest, ConverseResponse> = client.stream(
        headers,
        MethodSpec(
            "connectrpc.eliza.v1.ElizaService/Converse",
            com.connectrpc.eliza.v1.ConverseRequest::class,
            com.connectrpc.eliza.v1.ConverseResponse::class
        )
    )

    public override suspend fun introduce(headers: Headers):
        ServerOnlyStreamInterface<IntroduceRequest, IntroduceResponse> = client.serverStream(
        headers,
        MethodSpec(
            "connectrpc.eliza.v1.ElizaService/Introduce",
            com.connectrpc.eliza.v1.IntroduceRequest::class,
            com.connectrpc.eliza.v1.IntroduceResponse::class
        )
    )
}
Click to expand ElizaServiceClientInterface.kt
public interface ElizaServiceClientInterface {
    public suspend fun say(request: SayRequest, headers: Headers = emptyMap()):
        ResponseMessage<SayResponse>

    public suspend fun converse(headers: Headers = emptyMap()):
        BidirectionalStreamInterface<ConverseRequest, ConverseResponse>

    public suspend fun introduce(headers: Headers = emptyMap()):
        ServerOnlyStreamInterface<IntroduceRequest, IntroduceResponse>
}

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:

The 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.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4