url

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

This function provides a Kotlin domain-specific language (DSL) for building a URI. By using Kotlin's function literals with receiver, it enables a more expressive, English-like syntax when creating a URI.

This function is part of a DSL which means it can be used for configuration and setup in a structured and language-idiomatic way. The init parameter is a lambda with HttpUrlBuilder as its receiver. This allows the lambda to invoke the methods of HttpUrlBuilder without having to qualify them.

Example usage:

val uri = url {
scheme("https")
host("api.tomtom.com")
path("/api/service")
}

Return

the built URI.

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.


fun url(fromUri: URI, init: HttpUrlBuilder.() -> Unit): URI

Transforms a given URI using a Kotlin domain-specific language (DSL) builder. This function provides a way to modify an existing URI with a more expressive, English-like syntax.

The fromUri parameter is converted to an HttpUrlBuilder and 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.

Example usage:

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

This example creates a new instance based on oldUri, with modified path and added query parameter.

Return

the transformed URI.

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

Parameters

fromUri

the original URI to be transformed.

init

a lambda function where HttpUrlBuilder functions can be called.


fun url(fromString: String, init: HttpUrlBuilder.() -> Unit): URI

Transforms a given URL string into a URI using a Kotlin domain-specific language (DSL) builder. This function provides a way to create and configure a URI from a string with a more expressive, English-like syntax.

The fromString parameter is converted to a URI, then to an HttpUrlBuilder, and 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.

Example usage:

val newUri = url("https://api.tomtom.com/") {
path("/new/path")
queryParams {
add("param", "value")
}
}

This example modifies the path and adds a query parameter to the existing URL string.

Return

the transformed URI.

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

Parameters

fromString

the original URL string to be transformed.

init

a lambda function where HttpUrlBuilder functions can be called.