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

io.logto.sdk.core.http.HttpGet.kt Maven / Gradle / Ivy

The newest version!
package io.logto.sdk.core.http

import com.google.gson.JsonSyntaxException
import io.logto.sdk.core.exception.ResponseException

inline fun  httpGet(
    uri: String,
    headers: Map?,
    completion: HttpCompletion,
) {
    httpGet(uri, headers) httpRawGet@{ throwable, response ->
        throwable?.let {
            completion.onComplete(throwable, null)
            return@httpRawGet
        }
        try {
            completion.onComplete(null, gson.fromJson(response, T::class.java))
        } catch (jsonSyntaxException: JsonSyntaxException) {
            completion.onComplete(
                ResponseException(ResponseException.Type.ERROR_RESPONSE, jsonSyntaxException),
                null,
            )
        }
    }
}

inline fun  httpGet(uri: String, completion: HttpCompletion) =
    httpGet(uri, null, completion)

fun httpGet(uri: String, completion: HttpEmptyCompletion) = makeRequest(uri, null, null, completion)

@JvmName("httpRawGet")
fun httpGet(
    uri: String,
    headers: Map?,
    completion: HttpRawStringCompletion,
) = makeRequest(uri, null, headers, completion)

@JvmName("httpRawGet")
fun httpGet(uri: String, completion: HttpRawStringCompletion) = httpGet(uri, null, completion)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy