Getting Started
This guide walks through installing connect-kotlin-server, defining a gRPC service, and running the embedded Connect server end-to-end.
Requirements
Section titled “Requirements”- JDK 24 or newer.
- gRPC services generated with
grpc-java(anyio.grpc.BindableService).
Installation
Section titled “Installation”[!IMPORTANT] There are no published releases yet. The project is in alpha, versioned by commit — depend on a specific commit and treat every commit as potentially breaking (see the README for Versioning & compatibility).
Via JitPack
Section titled “Via JitPack”Pull a specific commit through JitPack:
repositories { maven { url = uri("https://jitpack.io") }}
dependencies { // Replace <commit> with the exact short commit SHA you want to pin to. implementation("com.github.cgardev:connect-kotlin-server:<commit>")}Local snapshot build
Section titled “Local snapshot build”Or clone the repository and publish to your local Maven repository:
git clone https://github.com/cgardev/connect-kotlin-server.gitcd connect-kotlin-server./gradlew :project:lib-connect-server:publishToMavenLocalThen depend on the snapshot in your build.gradle.kts:
repositories { mavenLocal()}
dependencies { implementation("io.github.cgardev:connect-kotlin-server:0.0.0-SNAPSHOT")}Defining a service
Section titled “Defining a service”Start by writing a Protobuf service definition. Here’s the demo service from the example:
syntax = "proto3";
package cgardev.example.v1;
option java_multiple_files = true;option java_package = "io.github.cgardev.example.v1";
service EchoService { rpc Echo(EchoRequest) returns (EchoResponse);
rpc GetServerInfo(GetServerInfoRequest) returns (ServerInfo) { option idempotency_level = NO_SIDE_EFFECTS; }}
message EchoRequest { string message = 1;}
message EchoResponse { string message = 1;}
message GetServerInfoRequest {}
message ServerInfo { string name = 1; string version = 2;}[!TIP] Mark unary methods with
idempotency_level = NO_SIDE_EFFECTSto enableGETrequest support.
Generate the gRPC stubs using protoc and the grpc-java plugin. The example project includes protobuf-gradle-plugin configured to do this automatically.
Implementing the service
Section titled “Implementing the service”Extend the generated gRPC base class and implement the service methods:
package io.github.cgardev.example.demo
import io.github.cgardev.example.v1.EchoRequestimport io.github.cgardev.example.v1.EchoResponseimport io.github.cgardev.example.v1.EchoServiceGrpcimport io.github.cgardev.example.v1.GetServerInfoRequestimport io.github.cgardev.example.v1.ServerInfoimport io.grpc.stub.StreamObserverimport org.springframework.stereotype.Component
@Componentclass EchoService : EchoServiceGrpc.EchoServiceImplBase() {
override fun echo(request: EchoRequest, responseObserver: StreamObserver<EchoResponse>) { responseObserver.onNext( EchoResponse.newBuilder().setMessage("echo: ${request.message}").build() ) responseObserver.onCompleted() }
override fun getServerInfo(request: GetServerInfoRequest, responseObserver: StreamObserver<ServerInfo>) { responseObserver.onNext( ServerInfo.newBuilder() .setName("connect-kotlin-server") .setVersion("0.1.0") .build() ) responseObserver.onCompleted() }}Running with Spring Boot
Section titled “Running with Spring Boot”The simplest path is the Spring Boot auto-configuration starter, which discovers your BindableService beans and hosts them over Connect automatically.
Add the dependency:
dependencies { implementation("io.github.cgardev:connect-kotlin-server-spring-boot-autoconfigure:<commit>") implementation("org.springframework.boot:spring-boot-starter") // ... your gRPC stubs and proto dependencies}Configure the server in application.properties:
spring.application.name=my-appspring.main.web-application-type=noneconnect.server.port=8080No wiring code needed — the starter auto-configures the server and manages its lifecycle through Spring’s SmartLifecycle. Boot the application:
./gradlew bootRunThe server binds Netty (not a servlet container) and hosts your services over Connect, Connect-streaming, and gRPC-Web on port 8080.
Running without Spring
Section titled “Running without Spring”For standalone applications, use ConnectServer directly:
import io.github.cgardev.library.connect.ConnectServerimport io.github.cgardev.library.connect.config.ConnectServerConfig
fun main() { val server = ConnectServer( services = listOf(EchoService()), config = ConnectServerConfig(port = 8080), ) server.start() Runtime.getRuntime().addShutdownHook(Thread { server.close() })}ConnectServer takes:
services: aList<BindableService>— your gRPC implementationsinterceptors: optionalList<ServerInterceptor>for the in-process gRPC pipelineconfig: aConnectServerConfigwith tuning options (port,host,cors, compression settings, etc.)
Call start() to bind Netty and host the in-process gRPC channel, and close() to shut down gracefully.
Testing the server
Section titled “Testing the server”Once the server is running, hit it with any HTTP client. The example server exposes two methods:
Connect unary (POST with JSON)
Section titled “Connect unary (POST with JSON)”curl -X POST http://localhost:8080/cgardev.example.v1.EchoService/Echo \ -H 'Content-Type: application/json' \ -d '{"message":"hello"}'Response:
{"message":"echo: hello"}GET idempotent method
Section titled “GET idempotent method”Methods marked idempotency_level = NO_SIDE_EFFECTS can be called via GET:
curl 'http://localhost:8080/cgardev.example.v1.EchoService/GetServerInfo?encoding=json&message=%7B%7D'Response:
{"name":"connect-kotlin-server","version":"0.1.0"}[!NOTE] The
encoding=jsonandmessage=query parameters are required for all GET requests. Themessageparameter carries the request body, URL-encoded.
Running the example project
Section titled “Running the example project”The repository includes a complete Spring Boot example at :project:app-server-spring. Clone the repository and run it:
git clone https://github.com/cgardev/connect-kotlin-server.gitcd connect-kotlin-server./gradlew :project:app-server-spring:bootRunThe example exposes the EchoService with additional demo methods (streaming and error handling). Hitting the same endpoints above will work, and you can explore the source in project/app-server-spring.
Next steps
Section titled “Next steps”- Learn about Spring Boot configuration for tuning the server.
- Explore protocol support for gRPC-Web, Connect streaming, and error handling.
- See the API reference for
ConnectServerconfiguration and hooks.