{"id":18066925,"url":"https://github.com/ichizero/connect-ktor","last_synced_at":"2025-08-19T10:31:12.659Z","repository":{"id":259796394,"uuid":"875731922","full_name":"ichizero/connect-ktor","owner":"ichizero","description":"Connect-Ktor: Bring Connect Protocol support to your Ktor servers.","archived":false,"fork":false,"pushed_at":"2024-12-15T18:09:45.000Z","size":158,"stargazers_count":9,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-12-15T19:19:22.927Z","etag":null,"topics":["connectrpc","grpc","java","kotlin","ktor","ktor-server","protobuf"],"latest_commit_sha":null,"homepage":"","language":"Kotlin","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ichizero.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-10-20T17:49:17.000Z","updated_at":"2024-12-15T18:09:14.000Z","dependencies_parsed_at":"2024-12-08T10:18:05.990Z","dependency_job_id":"f4dfa947-e8d7-4295-b86b-4598dbfd2a8c","html_url":"https://github.com/ichizero/connect-ktor","commit_stats":null,"previous_names":["ichizero/connect-ktor"],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Fconnect-ktor","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Fconnect-ktor/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Fconnect-ktor/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ichizero%2Fconnect-ktor/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ichizero","download_url":"https://codeload.github.com/ichizero/connect-ktor/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":230345676,"owners_count":18211993,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["connectrpc","grpc","java","kotlin","ktor","ktor-server","protobuf"],"created_at":"2024-10-31T07:05:44.989Z","updated_at":"2025-08-19T10:31:12.603Z","avatar_url":"https://github.com/ichizero.png","language":"Kotlin","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Connect-Ktor\n\n[![Maven Central Version](https://img.shields.io/maven-central/v/io.github.ichizero/connect-ktor)](https://central.sonatype.com/artifact/io.github.ichizero/connect-ktor)\n![CI](https://github.com/ichizero/connect-ktor/actions/workflows/ci.yml/badge.svg)\n[![License](https://img.shields.io/badge/License-Apache_2.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)\n\nConnect-Ktor is a library developed as an extension of\n[Connect-Kotlin](https://github.com/connectrpc/connect-kotlin)\nfor [Ktor](https://github.com/ktorio/ktor) servers.\nIt aims to gradually introduce the Connect Protocol into existing Ktor REST servers.\n\n## Features\n\n- connect-ktor\n  - Serialize/Deserialize Protocol Buffers JSON messages with Connect-Kotlin.\n  - Request validation support with [protovalidate](https://github.com/bufbuild/protovalidate).\n- protoc-gen-connect-ktor\n  - Generate Ktor route handler interfaces from Protocol Buffers service definitions.\n    \n\n## Usage\n\n### Add dependencies\n\nAdd the conenct-ktor library to your build.gradle.kts.\n\n```kotlin\ndependencies {\n    implementation(\"io.github.ichizero:connect-ktor:0.1.3\")\n}\n```\n\n### Generation\n\n#### 1. Setup protoc-gen-connect-ktor\n\nOn Linux or macOS, install the plugin with [Homebrew](https://brew.sh/).\n\n```bash\nbrew install ichizero/tap/protoc-gen-connect-ktor\n```\n\nAlternatively, you can download the plugin executable file from\n[releases](https://github.com/ichizero/connect-ktor/releases)\nand place it in your PATH.\n\n#### 2. Add plugins to your buf.gen.yaml\n\n```yaml\nversion: v2\nclean: true\nmanaged:\n  enabled: true\nplugins:\n  - remote: buf.build/protocolbuffers/java\n    out: path/to/code\n  - remote: buf.build/protocolbuffers/kotlin\n    out: path/to/code\n  - remote: buf.build/connectrpc/kotlin\n    out: path/to/code\n  - local: protoc-gen-connect-ktor\n    out: path/to/code\n```\n\n#### 3. Generate the Ktor route handler interfaces\n\n```bash\nbuf generate\n```\n\nGenerated handler interface is like below:\n\n```kotlin\npublic interface ElizaServiceHandlerInterface {\n    public suspend fun say(request: SayRequest, call: ApplicationCall): ResponseMessage\u003cSayResponse\u003e\n\n    public object Procedures {\n        @Resource(\"/connectrpc.eliza.v1.ElizaService/Say\")\n        public class Say\n    }\n}\n\npublic fun Route.elizaService(handler: ElizaServiceHandlerInterface) {\n    post\u003cElizaServiceHandler.Procedures.Say, SayRequest\u003e(handle(handler::say))\n}\n```\n\n### Implementation\n\n#### 1. Implement the generated handler interface \n\n```kotlin\nobject ElizaServiceHandler: ElizaServiceHandlerInterface {\n    override suspend fun say(\n        request: SayRequest,\n        call: ApplicationCall,\n    ): ResponseMessage\u003cSayResponse\u003e = ResponseMessage.Success(\n        sayResponse { sentence = request.sentence },\n        emptyMap(),\n        emptyMap(),\n    )\n}\n```\n\n#### 2. Register the handler in the Ktor server\n\n```kotlin\nfun main() {\n    embeddedServer(CIO, port = 8080) {\n        install(Resources)\n        routing {\n            install(ContentNegotiation) {\n                connectJson()\n            }\n            elizaService(ElizaServiceHandler)\n        }\n    }.start(wait = false)\n}\n```\n\n### Request Validation with protovalidate\n\nThe plugin named ProtoRequestValidation is provided to validate the request message with protovalidate.\nIf the request message is invalid, the server will respond with a 400 Bad Request status code with details.\n\n```protobuf\nsyntax = \"proto3\";\n\npackage stricteliza.v1;\n\nimport \"buf/validate/validate.proto\";\n\nmessage SayRequest {\n    string sentence = 1 [(buf.validate.field).string.max_len = 100];\n}\n```\n\n```kotlin\nfun main() {\n    embeddedServer(CIO, port = 8080) {\n        install(Resources)\n        install(StatusPages) {\n            exception\u003cProtoRequestValidationException\u003e { call, cause -\u003e\n                call.respondBytes(\n                    bytes = cause.toErrorJsonBytes(),\n                    status = HttpStatusCode.BadRequest,\n                    contentType = ContentType.Application.Json,\n                )\n            }\n        }\n        routing {\n            install(ContentNegotiation) {\n                connectJson()\n            }\n            install(ProtoRequestValidation)\n            strictElizaService(StrictElizaServiceHandler)\n        }\n    }.start(wait = false)\n}\n```\n\n## License\n\nOffered under the [Apache 2 license](https://github.com/ichizero/connect-ktor/blob/main/LICENSE).\n\n## Acknowledgements\n\nI'm very grateful for the [Connect Protocol](https://github.com/connectrpc/connect-go),\n[Connect-Kotlin](https://github.com/connectrpc/connect-kotlin) and its authors.\nTheir pioneering work and contributions to the open-source community made the development of Connect-Ktor possible.\n\nI encourage you to try Connect-Ktor and experience a new level of communication with your Ktor server!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichizero%2Fconnect-ktor","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fichizero%2Fconnect-ktor","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fichizero%2Fconnect-ktor/lists"}