Codat.HTTP.Behaviour behaviour (codat v1.0.0)

Copy Markdown View Source

Behaviour that Codat.HTTP.Client satisfies, exposed for mocking in tests.

In your application tests you can swap the real HTTP client for Mox:

# test/test_helper.exs
Mox.defmock(Codat.MockHTTP, for: Codat.HTTP.Behaviour)

# in a test
Codat.MockHTTP
|> expect(:get, fn _config, "/companies", _opts ->
  {:ok, %{"results" => [], "pageNumber" => 1, "pageSize" => 100, "totalResults" => 0}}
end)

Configure the adapter per-config:

config = Codat.Config.new(http_adapter: Codat.MockHTTP)

Summary

Types

response()

@type response() :: {:ok, map() | list() | binary() | nil} | {:error, Codat.Error.t()}

Callbacks

delete(t, t, keyword)

@callback delete(Codat.Config.t(), String.t(), keyword()) :: response()

get(t, t, keyword)

@callback get(Codat.Config.t(), String.t(), keyword()) :: response()

patch(t, t, arg3, keyword)

@callback patch(Codat.Config.t(), String.t(), map() | list(), keyword()) :: response()

post(t, t, arg3, keyword)

@callback post(Codat.Config.t(), String.t(), map() | list(), keyword()) :: response()

put(t, t, arg3, keyword)

@callback put(Codat.Config.t(), String.t(), map() | list(), keyword()) :: response()