All Downloads are FREE. Search and download functionalities are using the official Maven repository.

commonMain.com.aallam.openai.client.internal.http.HttpRequester.kt Maven / Gradle / Ivy

There is a newer version: 4.0.0-beta01
Show newest version
package com.aallam.openai.client.internal.http

import com.aallam.openai.client.Closeable
import io.ktor.client.*
import io.ktor.client.request.*
import io.ktor.client.statement.*
import io.ktor.util.reflect.*

/**
 * Http request performer.
 */
internal interface HttpRequester : Closeable {

    /**
     * Perform an HTTP request and get a result.
     */
    suspend fun  perform(info: TypeInfo, block: suspend (HttpClient) -> HttpResponse): T

    /**
     * Perform an HTTP request and get a result.
     *
     * Note: [HttpResponse] instance shouldn't be passed outside of [block].
     */
    suspend fun  perform(
        builder: HttpRequestBuilder,
        block: suspend (response: HttpResponse) -> T
    )
}

/**
 * Perform an HTTP request and get a result
 */
internal suspend inline fun  HttpRequester.perform(noinline block: suspend (HttpClient) -> HttpResponse): T {
    return perform(typeInfo(), block)
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy