exrequester
exrequester copied to clipboard
Create a way to define module level headers
At the moment, if you have the same headers passed in all the functions of the same module, we need to duplicate these headers with each method.
There should be a way to create headers that are reused for each function in the same module.
One way of doing it at the moment is like so
defmodule HTTPBinSample do
use EXRequester
@shared_headers [
key1: :value1
]
@get "/status"
@headers [Authorization: :auth] ++ @shared_headers
defreq get_status do
response.headers |> IO.inspect
end
@get "/other"
@headers [Authorization: :auth] ++ @shared_headers
defreq get_other do
response.headers |> IO.inspect
end
end
It leverage the fact that modules attributes can still be treated as elixir instructions. This might be one way of doing it, however there maybe some consideration on why this is not a good idea.
the example you provided seems like a good workaround. Perhaps having @shared_headers and @headers merged could be part of the defreq macro and have it handled transparently but still have the flexibility of custom headers for a request when needed?