commonMain.com.algolia.client.transport.RequestConfig.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
import io.ktor.util.reflect.*
/** Defines a config object for a given request. */
public data class RequestConfig(
val method: RequestMethod,
val path: List,
val isRead: Boolean = false,
val headers: Map = emptyMap(),
val query: Map = emptyMap(),
val body: RequestBody? = null,
) {
public constructor(
method: RequestMethod,
path: String,
isRead: Boolean = false,
headers: Map = emptyMap(),
query: Map = emptyMap(),
body: RequestBody? = null,
) : this(
method = method,
path = path.split("/").filter { it.isNotBlank() },
isRead = isRead,
headers = headers,
query = query,
body = body,
)
}
/** Represents a request body with it type. */
public data class RequestBody(
val body: Any? = null,
val bodyType: TypeInfo,
)
/** Create a [RequestConfig] instance. */
public inline fun RequestConfig(
method: RequestMethod,
path: String,
isRead: Boolean = false,
headers: Map = emptyMap(),
query: Map = emptyMap(),
body: T?,
): RequestConfig = RequestConfig(
method = method,
path = path,
isRead = isRead,
headers = headers,
query = query,
body = body?.let { RequestBody(it, bodyType = typeInfo()) },
)
/** Create a [RequestConfig] instance. */
public inline fun RequestConfig(
method: RequestMethod,
path: List,
isRead: Boolean = false,
headers: Map = emptyMap(),
query: Map = emptyMap(),
body: T?,
): RequestConfig = RequestConfig(
method = method,
path = path,
isRead = isRead,
headers = headers,
query = query,
body = body?.let { RequestBody(it, bodyType = typeInfo()) },
)
© 2015 - 2024 Weber Informatics LLC | Privacy Policy