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

commonMain.com.paoapps.fifi.api.ApiHelper.kt Maven / Gradle / Ivy

Go to download

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)
            }
        }
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy