Skip to content

Docs for gRPC with Ktor #394

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/pages/kotlinx-rpc/rpc.tree
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
<toc-element topic="grpc-services.topic"/>
<toc-element topic="grpc-client.topic"/>
<toc-element topic="grpc-server.topic"/>
<toc-element topic="grpc-ktor-server.topic"/>
</toc-element>
</toc-element>
<toc-element topic="strict-mode.topic"/>
Expand Down
8 changes: 6 additions & 2 deletions docs/pages/kotlinx-rpc/topics/grpc-client.topic
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
-->

<!DOCTYPE topic
SYSTEM "https://resources.jetbrains.com/writerside/1.0/xhtml-entities.dtd">
<topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
Expand All @@ -21,11 +25,11 @@
val result = recognizer.recognize(image)
println("Recognized category: ${result.category}")

grpcClient.cancel()
grpcClient.close()
</code-block>
<list>
<li>
<code>usePlaintext()</code> - is a JVM binding to Java gRPC runtime. Other bindings are also present.
</li>
</list>
</topic>
</topic>
31 changes: 31 additions & 0 deletions docs/pages/kotlinx-rpc/topics/grpc-ktor-server.topic
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
- Copyright 2023-2025 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
-->

<!DOCTYPE topic
SYSTEM "https://resources.jetbrains.com/writerside/1.0/xhtml-entities.dtd">
<topic xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://resources.jetbrains.com/writerside/1.0/topic.v2.xsd"
title="Ktor Server" id="grpc-ktor-server">

<p>
Similarly to <a href="grpc-server.topic"/>,
you can use gRPC with Ktor:
</p>
<code-block lang="kotlin">
fun Application.module() {
grpc(port = PORT, configure = { /* ... */ }) {
registerService&lt;MyService&gt; { MyServiceImpl() }
}
}
</code-block>
<p>
<code>GrpcServer</code> instance is created and bound to the Ktor Application lifetime.
It can be accessed via <code>application.attributes[GrpcServerKey]</code>.
</p>
Add the Ktor dependency to your project:
<code-block lang="kotlin">
implementation("org.jetbrains.kotlinx:kotlinx-rpc-grpc-ktor-server:%kotlinx-rpc-version%")
</code-block>
</topic>