salemove_http_client v1.0.1 Salemove.HttpClient
Generic HTTP client built on top of Tesla and used to build specific JSON API HTTP clients with ability to configure them during runtime, using, for example, environment variables.
Example
defmodule Github do
use Salemove.HttpClient, base_url: "https://api.github.com/"
def user_repos(login, opts \ []) do
get("/user/" <> login <> "/repos", opts)
end
end
Github.user_repos("take-five")
Configuration options
There are number of available configuration options:
:base_url
- Base URL of service (including schema, i.e.https://api.github.com/
):adapter
- HTTP Adapter module, defaults toTesla.Adapter.Hackney
:adapter_options
- adapter specific options, see documentation for concrete adapter:json
- JSON encoding/decoding options. If omitted, default options are used - seeTesla.Middleware.JSON
. If set tofalse
, request body is sent as application/x-www-form-urlencoded not JSON.:retry
- Retry few times in case of connection refused error. SeeTesla.Middleware.Retry
.:stats
- StatsD instrumenting options. SeeTesla.StatsD
for more details.:username
- along with:password
option adds basic authentication to all requests. SeeTesla.Middleware.BasicAuth
.:password
- see:username
.:log
- Logging options, seeSalemove.HttpClient.Middleware.Logger
HTTP client can be configured at runtime and at compile time via configuration files. Note,
that you can use {:system, env_name}
tuples to configure the client
Configuration via request options
You can pass additional Keyword
argument to request functions:
Github.user_repos("take-five", adapter: Tesla.Mock, base_url: "http://mocked-gh/")
Configuration via config files
In config/config.exs
:
config :salemove_http_client,
adapter: Tesla.Mock,
base_url: "http://mocked-gh/"
Link to this section Summary
Link to this section Types
Link to this type
option()
option() :: {:method, Tesla.Env.method()} | {:url, Tesla.Env.url()} | {:query, Tesla.Env.query()} | {:headers, Tesla.Env.headers()} | {:body, Tesla.Env.body()} | {:opts, Tesla.Env.opts()}
Client or request-specific options