How do I set up the `HttpClient` with kotlinx.seri...
# ktor
d
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
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
Seems a bit boilerplaty to copy an instance of the httpclient for every separate api call we make