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

commonMain.com.algolia.client.transport.RequestConfig.kt Maven / Gradle / Ivy

Go to download

"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."

There is a newer version: 3.10.1
Show newest version
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