Maxwell.Middleware.BaseUrl (maxwell v2.4.0) View Source

Sets the base url for all requests in this module.

You may provide any valid URL, and it will be parsed into it's requisite parts and assigned to the corresponding fields in the connection.

Providing a path in the URL will be treated as if it's a base path for all requests. If you subsequently create a connection and use put_path, the base path set in this middleware will be prepended to the path provided to put_path.

A base url is not valid if no host is set. You may omit the scheme, and it will default to http://.

Examples

iex> opts = Maxwell.Middleware.BaseUrl.init("http://example.com")
...> Maxwell.Middleware.BaseUrl.request(Maxwell.Conn.new("/foo"), opts)
%Maxwell.Conn{url: "http://example.com", path: "/foo"}

iex> opts = Maxwell.Middleware.BaseUrl.init("http://example.com/api/?version=1")
...> Maxwell.Middleware.BaseUrl.request(Maxwell.Conn.new("/users"), opts)
%Maxwell.Conn{url: "http://example.com", path: "/api/users", query_string: %{"version" => "1"}}