KtorDsl

object KtorDsl

A DSL object providing factory methods and utilities for Ktor HttpClient operations.

Supports both suspending and blocking HTTP request patterns with automatic client lifecycle management.

Functions

Link copied to clipboard
fun <T> blockingGet(url: String, setUp: HttpRequestBuilder.() -> Unit = {}, block: suspend (HttpResponse) -> T): T

Performs a blocking HTTP GET request using a temporary HttpClient.

Link copied to clipboard
suspend fun <T> HttpClient.get(url: String, setUp: HttpRequestBuilder.() -> Unit = {}, block: suspend (HttpResponse) -> T): T

Performs an HTTP GET request on this HttpClient and passes the response to block.

Link copied to clipboard
suspend fun <T> httpClient(httpClient: HttpClient? = null, expectSuccess: Boolean = false, block: suspend (HttpClient) -> T): T

Executes block with an HttpClient passed as a parameter. If httpClient is null, a new client is created and automatically closed after the block completes.

Link copied to clipboard
fun newHttpClient(expectSuccess: Boolean = false): HttpClient

Creates a new HttpClient configured with HttpTimeout support.

Link copied to clipboard
suspend fun <T> withHttpClient(httpClient: HttpClient? = null, expectSuccess: Boolean = false, block: suspend HttpClient.() -> T): T

Executes block with an HttpClient as the receiver. If httpClient is null, a new client is created and automatically closed after the block completes.