Parameters
Additional parameters for endpoints.
Endpoints declare mandatory parameters, such as the identifier of the resource. This abstract class allows to declare additional parameters in a type-safe manner.
Usage
In common code, declare a class that inherits from Parameters, and use it to declare the name and type of the available parameters:
class MyRequestParameters(data: ParameterStorage) : Parameters(data) {
var param1: String? by parameter()
var isSubscribed: Boolean by parameter("is_subscribed", default = false)
}Content copied to clipboard
To create a new parameter bundle, use the helper buildParameters function:
val example = buildParameters(::MyRequestParameters) {
param1 = "value"
isSubscribed = true
}Content copied to clipboard
The values can be accessed in a type-safe manner:
println(example.param1)Content copied to clipboard
The values can also be accessed via their string representation:
println(example.data["param1"])Content copied to clipboard