Skip to content

Commit 1624ac2

Browse files
committed
Documentation update for 0.8.0 (#351)
1 parent 655c204 commit 1624ac2

File tree

29 files changed

+1139
-555
lines changed

29 files changed

+1139
-555
lines changed

core/src/commonMain/kotlin/kotlinx/rpc/RpcCall.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,12 @@ package kotlinx.rpc
77
import kotlinx.rpc.descriptor.RpcServiceDescriptor
88

99
/**
10-
* Represents a method or field call of an RPC service.
10+
* Represents a method call from an RPC service.
1111
*
1212
* @property descriptor [RpcServiceDescriptor] of a service that made the call.
13-
* @property callableName The name of the callable. Can be the name of the method or field.
13+
* @property callableName The name of the method being called.
1414
* @property data The data for the call.
15-
* @property serviceId id of the service, that made the call.
15+
* @property serviceId The id of the service that made the call.
1616
*/
1717
public data class RpcCall(
1818
val descriptor: RpcServiceDescriptor<*>,

core/src/commonMain/kotlin/kotlinx/rpc/RpcClient.kt

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,11 @@
44

55
package kotlinx.rpc
66

7-
import kotlinx.coroutines.CoroutineScope
87
import kotlinx.coroutines.flow.Flow
98

109
/**
1110
* [RpcClient] represents an abstraction of an RPC client, that can handle requests from several RPC services,
1211
* transform them, send to the server and handle responses and errors.
13-
* [CoroutineScope] defines the lifetime of the client.
1412
*/
1513
public interface RpcClient {
1614
/**
@@ -19,7 +17,7 @@ public interface RpcClient {
1917
* @param T type of the result
2018
* @param call an object that contains all required information about the called method,
2119
* that is needed to route it properly to the server.
22-
* @return actual result of the call, for example, data from the server.
20+
* @return result of the call, for example, data from the server.
2321
*/
2422
public suspend fun <T> call(call: RpcCall): T
2523

@@ -30,7 +28,7 @@ public interface RpcClient {
3028
* @param T type of the result
3129
* @param call an object that contains all required information about the called method,
3230
* that is needed to route it properly to the server.
33-
* @return the actual result of the call, for example, data from the server
31+
* @return result of the call, for example, data from the server
3432
*/
3533
public fun <T> callServerStreaming(call: RpcCall): Flow<T>
3634
}

core/src/commonMain/kotlin/kotlinx/rpc/RpcServer.kt

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,32 @@ import kotlin.reflect.KClass
1313
*/
1414
public interface RpcServer {
1515
/**
16-
* Registers new service to the server. Server will route all designated messages to it.
16+
* Registers new service. Server will route all designated messages to it.
1717
* Service of any type should be unique on the server, but RpcServer doesn't specify the actual retention policy.
1818
*
1919
* @param Service the exact type of the server to be registered.
20-
* For example, for service with `MyService` interface and `MyServiceImpl` implementation,
21-
* type `MyService` should be specified explicitly.
20+
* For example, for a service with `MyService` interface and `MyServiceImpl` implementation
21+
* the type `MyService` should be specified explicitly.
2222
* @param serviceKClass [KClass] of the [Service].
2323
* @param serviceFactory function that produces the actual implementation of the service that will handle the calls.
24+
*
25+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
2426
*/
2527
public fun <@Rpc Service : Any> registerService(
2628
serviceKClass: KClass<Service>,
2729
serviceFactory: () -> Service,
2830
)
2931

32+
/**
33+
* Deregisters a service. Server will stop routing messages to it.
34+
*
35+
* @param Service the exact type of the server to be deregistered, the same one that was used for registration.
36+
* For example, for a service with `MyService` interface and `MyServiceImpl` implementation
37+
* the type `MyService` should be specified explicitly.
38+
* @param serviceKClass [KClass] of the [Service].
39+
*
40+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
41+
*/
3042
public fun <@Rpc Service : Any> deregisterService(
3143
serviceKClass: KClass<Service>,
3244
)
@@ -37,9 +49,11 @@ public interface RpcServer {
3749
* Service of any type should be unique on the server, but RpcServer doesn't specify the actual retention policy.
3850
*
3951
* @param Service the exact type of the server to be registered.
40-
* For example, for service with `MyService` interface and `MyServiceImpl` implementation,
41-
* type `MyService` should be specified explicitly.
52+
* For example, for a service with `MyService` interface and `MyServiceImpl` implementation
53+
* the type `MyService` should be specified explicitly.
4254
* @param serviceFactory function that produces the actual implementation of the service that will handle the calls.
55+
*
56+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
4357
*/
4458
public inline fun <@Rpc reified Service : Any> RpcServer.registerService(
4559
noinline serviceFactory: () -> Service,

core/src/commonMain/kotlin/kotlinx/rpc/annotations/CheckedTypeAnnotation.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,11 @@
55
package kotlinx.rpc.annotations
66

77
/**
8-
* Marks an annotation as a one that marks
9-
* a type argument as a one that requires its resolved type to be annotated this annotation.
8+
* Meta annotation.
9+
* Used to perform [annotation type-safety](https://kotlin.github.io/kotlinx-rpc/annotation-type-safety.html) checks.
10+
*
11+
* When an annotation class (for example, `@X`) is marked with `@CheckedTypeAnnotation` -
12+
* Any other type can be marked with `@X` to perform safety checks on type parameters that are also marked with `@X`.
1013
*
1114
* Example:
1215
* ```kotlin

core/src/commonMain/kotlin/kotlinx/rpc/annotations/Rpc.kt

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,24 @@ package kotlinx.rpc.annotations
88
* Every [Rpc] annotated interface will have a code generation process run on it,
99
* making the interface effectively usable for RPC calls.
1010
*
11-
* Example usage:
11+
* Example usage.
12+
*
13+
* Define an interface and mark it with `@Rpc`.
14+
* Compiler plugin will ensure that all declarations inside the interface are valid.
1215
* ```kotlin
13-
* // common code
1416
* @Rpc
1517
* interface MyService {
1618
* suspend fun sayHello(firstName: String, lastName: String, age: Int): String
1719
* }
18-
* // client code
20+
* ```
21+
* On the client side use [kotlinx.rpc.RpcClient] to get a generated instance of the service, and use it to make calls:
22+
* ```kotlin
1923
* val rpcClient: RpcClient
2024
* val myService = rpcClient.withService<MyService>()
2125
* val greetingFromServer = myService.sayHello("Alex", "Smith", 35)
22-
* // server code
26+
* ```
27+
* On the server side, define an implementation of this interface and register it on an [kotlinx.rpc.RpcServer]:
28+
* ```kotlin
2329
* class MyServiceImpl : MyService {
2430
* override suspend fun sayHello(firstName: String, lastName: String, age: Int): String {
2531
* return "Hello, $firstName $lastName, of age $age. I am your server!"
@@ -28,6 +34,11 @@ package kotlinx.rpc.annotations
2834
* val server: RpcServer
2935
* server.registerService<MyService> { MyServiceImpl() }
3036
* ```
37+
*
38+
* @see kotlinx.rpc.RpcClient
39+
* @see kotlinx.rpc.RpcServer
40+
* @see CheckedTypeAnnotation
41+
* @see kotlinx.rpc.withService
3142
*/
3243
@CheckedTypeAnnotation
3344
@Target(AnnotationTarget.CLASS, AnnotationTarget.ANNOTATION_CLASS, AnnotationTarget.TYPE_PARAMETER)

core/src/commonMain/kotlin/kotlinx/rpc/withService.kt

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,21 +12,25 @@ import kotlin.reflect.KClass
1212
import kotlin.reflect.KType
1313

1414
/**
15-
* Creates instance of the generated service [T], that is able to communicate with server using [RpcClient].
15+
* Creates an instance of the generated service [T], that is able to communicate with a server using this [RpcClient].
1616
*
1717
* @param T the exact type of the service to be created.
1818
* @return instance of the generated service.
19+
*
20+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
1921
*/
2022
public inline fun <@Rpc reified T : Any> RpcClient.withService(): T {
2123
return withService(T::class)
2224
}
2325

2426
/**
25-
* Creates instance of the generated service [T], that is able to communicate with server using [RpcClient].
27+
* Creates an instance of the generated service [T], that is able to communicate with a server using this [RpcClient].
2628
*
2729
* @param T the exact type of the service to be created.
2830
* @param serviceKType [KType] of the service to be created.
2931
* @return instance of the generated service.
32+
*
33+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
3034
*/
3135
public fun <@Rpc T : Any> RpcClient.withService(serviceKType: KType): T {
3236
return withService(serviceKType.rpcInternalKClass())
@@ -39,11 +43,13 @@ public fun <@Rpc T : Any> RpcClient.withService(serviceKType: KType): T {
3943
private val SERVICE_ID = atomic(0L)
4044

4145
/**
42-
* Creates instance of the generated service [T], that is able to communicate with server using [RpcClient].
46+
* Creates an instance of the generated service [T], that is able to communicate with a server using this [RpcClient].
4347
*
4448
* @param T the exact type of the service to be created.
4549
* @param serviceKClass [KClass] of the service to be created.
4650
* @return instance of the generated service.
51+
*
52+
* @see kotlinx.rpc.annotations.CheckedTypeAnnotation
4753
*/
4854
public fun <@Rpc T : Any> RpcClient.withService(serviceKClass: KClass<T>): T {
4955
val descriptor = serviceDescriptorOf(serviceKClass)

docs/pages/kotlinx-rpc/rpc.tree

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,11 @@
2424
<toc-element toc-title="kRPC">
2525
<toc-element topic="configuration.topic"/>
2626
<toc-element topic="features.topic"/>
27-
<toc-element topic="transport.topic"/>
27+
<toc-element topic="krpc-client.topic"/>
28+
<toc-element topic="krpc-server.topic"/>
29+
<toc-element topic="transport.topic">
30+
<toc-element topic="krpc-ktor.topic"/>
31+
</toc-element>
2832
</toc-element>
2933
<toc-element toc-title="gRPC">
3034
<toc-element topic="grpc-configuration.topic"/>
@@ -36,6 +40,7 @@
3640
<toc-element topic="strict-mode.topic"/>
3741
<toc-element topic="versions.topic"/>
3842
<toc-element toc-title="Migration guides">
43+
<toc-element topic="0-8-0.topic"/>
3944
<toc-element topic="0-6-0.topic"/>
4045
<toc-element topic="0-5-0.topic"/>
4146
<toc-element topic="0-4-0.topic"/>

0 commit comments

Comments
 (0)