Routemaster Client v0.3.0 Routemaster.Middleware.BaseUrl View Source
Dynamic base URL middleware.
Used in place of Tesla’s builtin BaseUrl middleware because that freezes the URL at compile time and requires a clunky workaround to read it dynamically.
A dynamic BaseUrlFromConfig
middleware is provided by Tesla (undocumented), but it’s quite rigid
on where to find the configured URL, and since we control the requirements
for this library it’s easier to just use this custom middleware, that is
more specific to our use case.
Also, at the moment we’re making some strong assumptions on the format of the configured URL (no trailing slash), so that the implementation of this middleware can be simpler and faster. This will break if people configure URLs with a trailing slash.
This middleware does not require any option and automatically reads the base URL from the application configuration.
Example:
defmodule MyClient do
use Tesla
plug Routemaster.Middleware.BaseUrl
end