mutate

fun URI.mutate(init: HttpUrlBuilder.() -> Unit): URI

Creates a new URI by modifying an existing one using a Kotlin domain-specific language (DSL) builder. This function provides a way to create a new URI from an existing one with a fluent, English-like syntax.

The original URI is converted to an HttpUrlBuilder, then the init lambda with HttpUrlBuilder as its receiver is applied. This allows the lambda to invoke the methods of HttpUrlBuilder without having to qualify them.

Note: This method does not modify the original URI. Instead, it returns a new URI instance with the modifications applied.

Example usage:

val newUri = oldUri.mutate {
path("/new/path")
queryParams {
add("param", "value")
}
}

This example creates a new URI with the modified path and added query parameter, while leaving the oldUri unchanged.

Return

a new URI with the modifications applied.

Important: This is a Public Preview API. It may be changed or removed at any time.

Parameters

init

a lambda function where HttpUrlBuilder functions can be called.