View Source AppStore.HTTPClient behaviour (App Store v0.3.1)
HTTPClient behaviour for AppStore
Build your own HTTP client:
defmodule MyApp.AwesomeHTTPClient do
@behaviour AppStore.HTTPClient
@impl true
def request(method, uri, body, headers \ []) do
# request the server
if success
{:ok,
%{
status: response.status,
headers: response.headers,
body: response.body,
data: nil
}}
else
{:error, error} ->
{:error,
%{
code: :server_error,
detail: error
}
}
end
end
end
Then Use the custom HTTP while building the client:
app_store =
AppStore.build(
api: [
http_client: MyApp.AwesomeHTTPClient
]
)
See AppStore.HTTPClient.DefaultClient
for a reference implementation.
Summary
Types
@type http_method() :: :get | :put
@type http_response() :: %{ data: map(), body: binary(), headers: http_headers(), status: non_neg_integer() }
Callbacks
@callback request( method :: http_method(), uri :: URI.t(), body :: String.t(), headers :: http_headers() ) :: {:ok, http_response()} | {:error, http_error()}
Functions
@spec perform_request( module(), String.t(), http_method(), URI.t(), nil | String.t() | map() ) :: {:ok, http_response()} | {:error, http_error()}