Adding a header to a smithy client request? #328
-
I've written my IDL; generated an http client... to be able to use it to contact our internal services, I'd need to be to able to add a header along the lines of;
Schematically...
It wasn't obvious to me, how I would do this or where the right insertion point might be? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 5 replies
-
Hey @Quafadas , good to see you here again. Hopefully, I'm able to help. For more info on why we don't have out-of-the-box support for authentication, see #127. In the meantime, I'll provide you with a way to write a http4s middleware to tweak your http4s client to add the headers, it should be relatively simple. Updated: Relevant bits:
In http4s, a client is just a function from a Note, I did compile it, but I did not run it! Hope it works out for you. |
Beta Was this translation helpful? Give feedback.
-
After some evolution, I ended here:
Which is then very neat at the callsite.
My own use case is that I have lots of (different) internal services, which all have the same login mechanism. This makes it easy to instantiate a bunch of clients that may choose to share logins and tokens depending on config. Tokens are cached for the duration of their validity, which hopefully means not continually repeating login requests. |
Beta Was this translation helpful? Give feedback.
Hey @Quafadas , good to see you here again. Hopefully, I'm able to help.
For more info on why we don't have out-of-the-box support for authentication, see #127. In the meantime, I'll provide you with a way to write a http4s middleware to tweak your http4s client to add the headers, it should be relatively simple.
Updated:
Relevant bits: