httpClient

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.

Return

the result of block

Parameters

httpClient

an optional pre-existing client to reuse; if null, a new client is created

expectSuccess

if true, non-2xx responses will throw exceptions (only applies to newly created clients)

block

the suspending block to execute, receiving the client as a parameter

Type Parameters

T

the return type of the block