commonMain.com.paoapps.fifi.api.ApiHelper.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of fifi-common Show documentation
Show all versions of fifi-common Show documentation
Kotlin Multiplatform Mobile framework for optimal code sharing between iOS and Android.
The newest version!
package com.paoapps.fifi.api
import io.ktor.client.HttpClient
import io.ktor.client.request.HttpRequestBuilder
import io.ktor.client.request.header
import io.ktor.client.request.headers
import org.koin.core.component.KoinComponent
open class ApiHelper(
val client: HttpClient,
private val additionalHeaders: Map = emptyMap(),
): KoinComponent {
open fun headers(authHeader: String? = null): Map {
val mutableMap = additionalHeaders.toMutableMap()
authHeader?.let { mutableMap["Authorization"] = it }
return mutableMap
}
fun createHeaders(httpRequestBuilder: HttpRequestBuilder, authHeader: String? = null) {
httpRequestBuilder.headers {
headers(authHeader).entries.forEach {
httpRequestBuilder.header(it.key, it.value)
}
}
}
}