commonMain.com.algolia.client.transport.internal.Requester.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
Show all versions of algoliasearch-client-kotlin-jvm Show documentation
"Algolia is a powerful search-as-a-service solution, made easy to use with API clients, UI libraries, and pre-built integrations. Algolia API Client for Kotlin lets you easily use the Algolia Search REST API from your JVM project, such as Android or backend implementations."
package com.algolia.client.transport.internal
import com.algolia.client.BuildConfig
import com.algolia.client.configuration.AgentSegment
import com.algolia.client.configuration.ClientOptions
import com.algolia.client.configuration.Host
import com.algolia.client.configuration.internal.AlgoliaAgent
import com.algolia.client.configuration.internal.algoliaHttpClient
import com.algolia.client.configuration.internal.platformAgentSegment
import com.algolia.client.transport.RequestConfig
import com.algolia.client.transport.RequestOptions
import com.algolia.client.transport.Requester
import io.ktor.util.reflect.*
/**
* Executes a network request with the specified configuration and options, then returns the
* result as the specified type.
*
* This is a suspending function, which means it can be used with coroutines for asynchronous
* execution.
*
* @param T The type of the result expected from the request. This should match the returnType
* parameter.
* @param requestConfig The configuration for the network request, including the URL, method,
* headers, and body.
* @param requestOptions Optional settings for the request execution, such as timeouts or cache
* policies. Default value is null.
*/
internal suspend inline fun Requester.execute(
requestConfig: RequestConfig,
requestOptions: RequestOptions? = null,
): T {
return execute(requestConfig, requestOptions, typeInfo())
}
/**
* Creates a [Requester] instance.
*/
internal fun requesterOf(
clientName: String,
appId: String,
apiKey: String,
options: ClientOptions,
defaultHosts: () -> List,
) = options.requester ?: KtorRequester(
httpClient = algoliaHttpClient(
appId = appId,
apiKey = apiKey,
options = options,
agent = AlgoliaAgent(BuildConfig.VERSION).apply {
add(platformAgentSegment())
add(AgentSegment(clientName, BuildConfig.VERSION))
},
),
connectTimeout = options.connectTimeout,
readTimeout = options.readTimeout,
writeTimeout = options.writeTimeout,
hosts = options.hosts ?: defaultHosts(),
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy