https://kotlinlang.org logo
#ktor
Title
# ktor
d

dylan

04/29/2020, 3:06 PM
How do I set up the
HttpClient
with kotlinx.serializtion where every api endpoint has a custom vendor specific content-type? if I use the
accept()
function with multiple content-types they are also added to the accept header on the request which I don't want because we already specifiy that where I make the actual request. So api call
A
needs to send
Accept: application/vnd.a
and in return will get the
Content-Type: application/vnd.a
back in the response header and
B
sends
application/vnd.b
and is going to get
application/vnd.b
back. but I get NoTransformationFoundException: ByteBufferChannel => Serializable data class.
a

Ayman Izzeldin

04/29/2020, 6:40 PM
if I understand the question correctly, you can create a copy of the http client, and reconfigure it (this new client will reuse the same underlying engine.) Something along the lines of:
Copy code
val apiAClient = myHttpClient.config {
    Json { acceptContentTypes = acceptContentTypes + ContentType.parse("application/vnd.a") }
}
d

dylan

04/29/2020, 9:13 PM
Seems a bit boilerplaty to copy an instance of the httpclient for every separate api call we make
7 Views