request

inline suspend fun HttpClient.request(builder: HttpRequestBuilder = HttpRequestBuilder()): HttpResponse

Executes an HTTP request using the provided HttpRequestBuilder configuration.

This function sends a request with parameters specified in the builder, allowing customization of request settings such as URL, HTTP method, headers, and body.

Usage Example

val client = HttpClient()
val response = client.request {
url("https://ktor.io")
method = HttpMethod.Get
}

This example demonstrates making a GET request to "https://ktor.io".

Note

In addition to this generic HttpClient.request method, there are more specific extension functions, such as HttpClient.get, HttpClient.post, HttpClient.put, and HttpClient.delete, which are often more convenient for common HTTP methods.

Return

HttpResponse The response received from the server after executing the request.

For more details, see Making requests.

Parameters

builder

The HttpRequestBuilder used to configure request parameters. Defaults to an empty builder if none is provided.


inline suspend fun HttpClient.request(block: HttpRequestBuilder.() -> Unit): HttpResponse

Executes an HTTP request using the provided HttpRequestBuilder configuration.

This function sends a request with parameters specified in the block, allowing customization of request settings such as URL, HTTP method, headers, and body.

Usage Example

val client = HttpClient()
val response = client.request {
url("https://ktor.io")
method = HttpMethod.Get
}

This example demonstrates making a GET request to "https://ktor.io".

Note

In addition to this generic HttpClient.request method, there are more specific extension functions, such as HttpClient.get, HttpClient.post, HttpClient.put, and HttpClient.delete, which are often more convenient for common HTTP methods.

Return

HttpResponse The response received from the server after executing the request.

For more details, see Making requests.

Parameters

block

The HttpRequestBuilder block used to configure request parameters. Defaults to an empty builder if none is provided.


inline suspend fun HttpClient.request(urlString: String, block: HttpRequestBuilder.() -> Unit = {}): HttpResponse

Executes an HTTP request using the provided HttpRequestBuilder configuration.

This function sends a request to the urlString with parameters specified in the block, allowing customization of request settings such as URL, HTTP method, headers, and body.

Usage Example

val client = HttpClient()
val response = client.request("https://ktor.io") {
method = HttpMethod.Get
}

This example demonstrates making a GET request to "https://ktor.io".

Note

In addition to this generic HttpClient.request method, there are more specific extension functions, such as HttpClient.get, HttpClient.post, HttpClient.put, and HttpClient.delete, which are often more convenient for common HTTP methods.

Return

HttpResponse The response received from the server after executing the request.

For more details, see Making requests.

Parameters

urlString

The URL to which the request is sent.

block

The HttpRequestBuilder used to configure request parameters. Defaults to an empty builder if none is provided.


inline suspend fun HttpClient.request(url: Url, block: HttpRequestBuilder.() -> Unit = {}): HttpResponse

Executes an HTTP request using the provided HttpRequestBuilder configuration.

This function sends a request to url with parameters specified in the block, allowing customization of request settings such as URL, HTTP method, headers, and body.

Usage Example

val client = HttpClient()
val response = client.request("https://ktor.io") {
method = HttpMethod.Get
}

This example demonstrates making a GET request to "https://ktor.io".

Note

In addition to this generic HttpClient.request method, there are more specific extension functions, such as HttpClient.get, HttpClient.post, HttpClient.put, and HttpClient.delete, which are often more convenient for common HTTP methods.

Return

HttpResponse The response received from the server after executing the request.

For more details, see Making requests.

Parameters

url

The URL to which the request is sent.

block

The HttpRequestBuilder used to configure request parameters. Defaults to an empty builder if none is provided.


Creates an HttpRequestBuilder and configures it using block.

suspend fun <Error class: unknown class>.request(url: URL, block: <Error class: unknown class>.() -> Unit = {}): <Error class: unknown class>

Executes a HttpClient request, with the specified url as URL and an optional block receiving an HttpRequestBuilder for further configuring the request.