tesla icon indicating copy to clipboard operation
tesla copied to clipboard

Add Client.update_middleware/2 function

Open maciej-szlosarczyk opened this issue 3 years ago • 2 comments

I have seen this being a pain point a few times so maybe it's useful for someone else.

A typical use-case is the following:

A third-party library (i.e GitHub) exposes a function that returns a Tesla client, but I want to append a header or add logging/telemetry to it. Currently I need to write a wrapper for Tesla.Client.middleware/1 and Tesla.client/2, this merges the two into a single function.

maciej-szlosarczyk avatar Mar 13 '22 06:03 maciej-szlosarczyk

👋

I've found similar need when working on the OpenAPI generator and I've ended up with https://github.com/elixir-tesla/tesla/blob/openapi/lib/tesla/client.ex#L51-L72 (this code lives only in the openapi branch, nowhere near to be released yet)

Do you see the need for generic update_middleware or would insert be enough?

teamon avatar May 08 '22 08:05 teamon

Hey @teamon, for my use-case insert would work as well. Let me know if I should extract it from that branch and rework this PR with that or help in any other way.

maciej-szlosarczyk avatar May 16 '22 08:05 maciej-szlosarczyk