One question with regards to best practices: I'm i...
# ktor
h
One question with regards to best practices: I'm implementing a service which performs calls against the Twitter and Mastodon API. Should I create two different clients (with different credentials configured) or just one client (where credentials are configured on each call)?
s
I don’t know if this is a best practice, but my experience has been that when integrating with other APIs, one client per API works best. Each API tends to have its own quirks with regards to error handling, headers, serialisation, etc., and those things can often be more conveniently configured for the whole HTTP client than for an individual request.
đź‘Ť 1
For example, I use Jackson, and the Jackson configuration I want for deserialising responses from Twitter might be different from what I want when talking to Mastodon. The Jackson object mapper plugs in to the HTTP client as a plugin, so two different object mapper configs means two different HTTP clients.
I have experimented with reusing an HTTP client engine between multiple HTTP clients, though, in case it helps to share the low level resources like threads and connection pools. I don’t know if it’s worth it.
h
Thanks for the answer, this was also my gut feeling.