Skip to content

Latest commit

 

History

History
61 lines (52 loc) · 1.79 KB

File metadata and controls

61 lines (52 loc) · 1.79 KB

Route Versioning

When a product grows and evolves, dealing with backward and forward compatibility becomes essential. For these purposes, the library provides necessary wrappers around router-core with versioning support.

Warning This feature is experimental; migration steps might be required in the future.

How It Works

Every type of request with the router-versioning-core artifact now has its extension with a DSL builder for versioning:

val router = {
    routeProvider { /*...*/ }
    versioning { coroutineContext, payload -> Version(/* ... */) }

    routing {
        route("authorization") {
            requestResponseV("register") {
                // available from version 1 up to 2
                version(1) { payload ->
                    TODO()
                }

                // available from version 2 and onwards
                version(2) { payload ->
                    TODO()
                }
            }
        }
    }
}

Note
As for semantic versioning, you can also specify minor version for each new request within one major release if you need using version(version: Version, block: suspend (T) -> R).

Implementation

To implement this feature, add it to your dependencies as follows:

dependencies {
    implementation("com.y9vad9.rsocket.router:router-versioning-core:$version")
}

Serialization support

To use serialization feature, implement the following dependency:

dependencies {
    implementation("com.y9vad9.rsocket.router:router-versioning-serialization:$version")
}

Example

Here's example of how you can define type-safe requests with versioning support:

requestResponseV("register") {
    version<Foo, Bar>(1) { foo: Foo ->
        Bar(/* ... */)
    }
}