Jeff Tycz
02/12/2021, 1:45 AMsuspend inline fun <reified T> post(authKey: String, url: String, data: Any): T? {
val response = <http://_client.post|_client.post><HttpResponse>(url) {
header("Authorization", "Bearer $authKey")
contentType(ContentType.Application.Json)
body = data
}
when (response.status.value) {
in 300..399 -> throw RedirectResponseException(response)
in 400..499 -> throw ClientRequestException(response)
in 500..599 -> throw ServerResponseException(response)
}
if (response.status.value >= 600) {
throw ResponseException(response)
}
return response.receive<T>()
}
Is there a way to dynamically set the headers?tateisu
02/12/2021, 5:24 AMprivate suspend inline fun <reified T> post(
authKey: String,
url: String,
data: Any,
extraBuilder:HttpRequestBuilder.()->Unit ={}): T? {
val response = <http://_client.post|_client.post><HttpResponse>(url) {
header("Authorization", "Bearer $authKey")
contentType(ContentType.Application.Json)
body = data
extraBuilder()
}
tateisu
02/12/2021, 5:26 AMtateisu
02/12/2021, 5:29 AMHttpRequestBuilder.() -> Unit = {}
that is same to client.post() 's block
argument.