commonMain.com.algolia.client.transport.RequestConfig.kt Maven / Gradle / Ivy
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 - 2025 Weber Informatics LLC | Privacy Policy