You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Or you can call `router` function directly in the `RSocketRequestHandlerBuilder` context – it will automatically
35
-
install router on the given context.
27
+
> For now, it's available for JVM only, but as there is no JVM platform API used,
28
+
> new targets will be available [upon your request](https://github.com/y9vad9/rsocket-kotlin-router/issues/new).
36
29
37
-
### Routing Builder
38
-
You can define routes using bundled DSL-Builder functions:
30
+
Example of defining RSocket router:
39
31
```kotlin
40
-
fun RoutingBuilder.usersRoute(): Unit= route("users") {
41
-
// extension function that wraps RSocket `requestResponse` into `route` with given path.
42
-
requestResponse("get") { payload ->TODO() }
43
-
44
-
// ... other
32
+
val serverRouter = router {
33
+
routeSeparator ='.'
34
+
routeProvider { metadata:ByteReadPacket?->
35
+
metadata?.read(RoutingMetadata)?.tags?.first()
36
+
?:throwRSocketError.Invalid("No routing metadata was provided")
37
+
}
38
+
39
+
routing { // this: RoutingBuilder
40
+
route("authorization") {
41
+
requestResponse("register") { payload:Payload->
42
+
// just 4 example
43
+
println(payload.data.readText())
44
+
Payload.Empty
45
+
}
46
+
}
47
+
}
45
48
}
46
49
```
47
-
> **Note** <br>
48
-
> The library does not include the functionality to add routing to a `metadataPush` type of request. I am not sure
49
-
> how it should be exactly implemented (API), so your ideas are welcome. For now, I consider it a per-project responsibility.
50
-
### Interceptors
51
-
> **Warning** <br>
52
-
> Interceptors are experimental feature: API can be changed in the future.
53
-
54
-
#### Preprocessors
55
-
Preprocessors are utilities that run before the routing feature applies. For cases, when you need to transform input into something or propagate
56
-
values using coroutines – you can extend [`Preprocessor.Modifier`](https://github.com/y9vad9/rsocket-kotlin-router/blob/8bace098e0a47e3cf514eec0dfb702f7e4e13591/router-core/src/commonMain/kotlin/com.y9vad9.rsocket.router/interceptors/Interceptor.kt#L35) or [`Preprocessor.CoroutineContext`](https://github.com/y9vad9/rsocket-kotlin-router/blob/8bace098e0a47e3cf514eec0dfb702f7e4e13591/router-core/src/commonMain/kotlin/com.y9vad9.rsocket.router/interceptors/Interceptor.kt#L27). Here's an example:
50
+
51
+
See also what else is supported:
52
+
53
+
<detailsid="Interceptors">
54
+
<summary>Interceptors</summary>
55
+
<i>Interceptors are experimental feature: API can be changed in the future.</i>
56
+
57
+
<bid="Preprocessors">Preprocessors</b>
58
+
59
+
Preprocessors are utilities that run before routing feature applies. For cases, when you need to transform input into something or propagate
60
+
values using coroutines – you can extend [`Preprocessor.Modifier`](https://github.com/y9vad9/rsocket-kotlin-router/blob/2a794e9a8c5d2ac53cb87ea58cfbe4a2ecfa217d/router-core/src/commonMain/kotlin/com.y9vad9.rsocket.router/interceptors/Interceptor.kt#L39) or [`Preprocessor.CoroutineContext`](https://github.com/y9vad9/rsocket-kotlin-router/blob/master/router-core/src/commonMain/kotlin/com.y9vad9.rsocket.router/interceptors/Interceptor.kt#L31). Here's an example:
@@ -65,7 +69,8 @@ class MyCoroutineContextPreprocessor : Preprocessor.CoroutineContext {
65
69
}
66
70
```
67
71
68
-
#### Route Interceptors
72
+
<bid="RouteInterceptors">Route Interceptors</b>
73
+
69
74
In addition to the `Preprocessors`, `rsocket-kotlin-router` also provides API to intercept specific routes:
70
75
```kotlin
71
76
@OptIn(ExperimentalInterceptorsApi::class)
@@ -75,9 +80,61 @@ class MyRouteInterceptor : RouteInterceptor.Modifier {
75
80
}
76
81
}
77
82
```
78
-
It has the same abilities as Preprocessors. You can take a look at it [here](https://github.com/y9vad9/rsocket-kotlin-router/blob/8bace098e0a47e3cf514eec0dfb702f7e4e13591/router-core/src/commonMain/kotlin/com.y9vad9.rsocket.router/interceptors/Interceptor.kt#L45).
0 commit comments