ktor-client-core / io.ktor.client.request / HttpRequestBuilder

HttpRequestBuilder

class HttpRequestBuilder : HttpMessageBuilder

Class for building HttpRequestData.

Constructors

<init>

HttpRequestBuilder()

Class for building HttpRequestData.

Properties

attributes

val attributes: Attributes

Call specific attributes.

body

var body: Any

The body for this request. Initially EmptyContent.

executionContext

var executionContext: Job

A deferred used to control the execution of this request.

headers

val headers: HeadersBuilder

HeadersBuilder to configure the headers for this request.

method

var method: HttpMethod

HttpMethod used by this request. HttpMethod.Get by default.

url

val url: URLBuilder

URLBuilder to configure the URL for this request.

Functions

build

fun build(): HttpRequestData

Create immutable HttpRequestData

getCapabilityOrNull

fun <T : Any> getCapabilityOrNull(key: HttpClientEngineCapability<T>): T?

Retrieve capability by key.

setAttributes

fun setAttributes(block: Attributes.() -> Unit): Unit

Set request specific attributes specified by block.

setCapability

fun <T : Any> setCapability(key: HttpClientEngineCapability<T>, capability: T): Unit

Set capability configuration.

takeFrom

fun takeFrom(builder: HttpRequestBuilder): HttpRequestBuilder

Mutates this copying all the data but execution context from another builder using it as base.

takeFromWithExecutionContext

fun takeFromWithExecutionContext(builder: HttpRequestBuilder): HttpRequestBuilder

Mutates this copying all the data from another builder using it as base.

url

fun url(block: URLBuilder.(URLBuilder) -> Unit): Unit

Executes a block that configures the URLBuilder associated to this request.

Extension Properties

expectSuccess

var HttpRequestBuilder.expectSuccess: Boolean

host

var HttpRequestBuilder.host: String

Gets the associated URL's host.

port

var HttpRequestBuilder.port: Int

Gets the associated URL's port.

Extension Functions

accept

fun HttpRequestBuilder.accept(contentType: ContentType): Unit

Sets the Accept header with a specific contentType.

cookie

fun HttpRequestBuilder.cookie(name: String, value: String, maxAge: Int = 0, expires: GMTDate? = null, domain: String? = null, path: String? = null, secure: Boolean = false, httpOnly: Boolean = false, extensions: Map<String, String?> = emptyMap()): Unit

Sets a single header of key with a specific value if the value is not null.

header

fun HttpRequestBuilder.header(key: String, value: Any?): Unit

Sets a single header of key with a specific value if the value is not null.

headers

fun HttpRequestBuilder.headers(block: HeadersBuilder.() -> Unit): HeadersBuilder

Executes a block that configures the HeadersBuilder associated to this request.

parameter

fun HttpRequestBuilder.parameter(key: String, value: Any?): Unit

Sets a single URL query parameter of key with a specific value if the value is not null. Can not be used to set form parameters in the body.

takeFrom

fun HttpRequestBuilder.takeFrom(request: HttpRequest): HttpRequestBuilder

Mutates this copying all the data from another request using it as base.

fun HttpRequestBuilder.takeFrom(request: HttpRequestData): HttpRequestBuilder

Sets the HttpRequestBuilder from request.

timeout

fun HttpRequestBuilder.timeout(block: HttpTimeoutCapabilityConfiguration.() -> Unit): Unit

Adds timeout boundaries to the request. Requires HttpTimeout feature to be installed.

url

fun HttpRequestBuilder.url(block: URLBuilder.() -> Unit): Unit

Executes a block that configures the URLBuilder associated to this request.

fun HttpRequestBuilder.url(scheme: String = "http", host: String = "localhost", port: Int = DEFAULT_PORT, path: String = "/", block: URLBuilder.() -> Unit = {}): Unit

Sets the url using the specified scheme, host, port and path.

fun HttpRequestBuilder.url(urlString: String): Unit

Sets the HttpRequestBuilder.url from urlString.

fun HttpRequestBuilder.url(url: Url): Unit
fun HttpRequestBuilder.url(url: URL): URLBuilder

Sets the HttpRequestBuilder.url from url.

Companion Object Extension Functions

invoke

operator fun HttpRequestBuilder.Companion.invoke(block: URLBuilder.() -> Unit): HttpRequestBuilder

Executes a block that configures the URLBuilder associated to thisrequest.

operator fun HttpRequestBuilder.Companion.invoke(scheme: String = "http", host: String = "localhost", port: Int = DEFAULT_PORT, path: String = "/", block: URLBuilder.() -> Unit = {}): HttpRequestBuilder

Constructs a HttpRequestBuilder from URL information: scheme, host, port and path and optionally further configures it using block.

operator fun HttpRequestBuilder.Companion.invoke(url: URL): HttpRequestBuilder

Constructs a HttpRequestBuilder from url.