Mojito.Base behaviour (mojito v0.7.12) View Source

Provides a default implementation for Mojito functions.

This module is meant to be use'd in custom modules in order to wrap the functionalities provided by Mojiti. For example, this is very useful to build custom API clients around Mojito:

defmodule CustomAPI do
  use Mojito.Base
end

Link to this section Summary

Link to this section Types

Specs

body() :: String.t()

Specs

error() :: %Mojito.Error{message: String.t() | nil, reason: any()}

Specs

header() :: {String.t(), String.t()}

Specs

headers() :: [header()]

Specs

method() ::
  :head | :get | :post | :put | :patch | :delete | :options | String.t()

Specs

payload() :: String.t()

Specs

pool_opt() ::
  {:size, pos_integer()}
  | {:max_overflow, non_neg_integer()}
  | {:pools, pos_integer()}
  | {:strategy, :lifo | :fifo}

Specs

pool_opts() :: [pool_opt() | {:destinations, [{atom(), pool_opts()}]}]

Specs

request() :: %Mojito.Request{
  body: String.t() | nil,
  headers: headers() | nil,
  method: method(),
  opts: Keyword.t() | nil,
  url: String.t()
}

Specs

request_field() ::
  {:method, method()}
  | {:url, String.t()}
  | {:headers, headers()}
  | {:body, String.t()}
  | {:opts, Keyword.t()}

Specs

request_kwlist() :: [request_field()]

Specs

response() :: %Mojito.Response{
  body: String.t(),
  complete: boolean(),
  headers: headers(),
  size: term(),
  status_code: pos_integer()
}

Specs

url() :: String.t()

Link to this section Callbacks

Specs

delete(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

delete(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

delete(url(), headers(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

get(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

get(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

get(url(), headers(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

head(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

head(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

head(url(), headers(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

options(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

options(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()
Link to this callback

options(url, headers, t)

View Source

Specs

options(url(), headers(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

patch(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

patch(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()
Link to this callback

patch(url, headers, payload)

View Source

Specs

patch(url(), headers(), payload()) ::
  {:ok, response()} | {:error, error()} | no_return()
Link to this callback

patch(url, headers, payload, t)

View Source

Specs

patch(url(), headers(), payload(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

post(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

post(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()
Link to this callback

post(url, headers, payload)

View Source

Specs

post(url(), headers(), payload()) ::
  {:ok, response()} | {:error, error()} | no_return()
Link to this callback

post(url, headers, payload, t)

View Source

Specs

post(url(), headers(), payload(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

put(url()) :: {:ok, response()} | {:error, error()} | no_return()

Specs

put(url(), headers()) :: {:ok, response()} | {:error, error()} | no_return()
Link to this callback

put(url, headers, payload)

View Source

Specs

put(url(), headers(), payload()) ::
  {:ok, response()} | {:error, error()} | no_return()
Link to this callback

put(url, headers, payload, t)

View Source

Specs

put(url(), headers(), payload(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()

Specs

request(request() | request_kwlist()) :: {:ok, response()} | {:error, error()}

Specs

request(method(), url()) :: {:ok, response()} | {:error, error()} | no_return()
Link to this callback

request(method, url, headers)

View Source

Specs

request(method(), url(), headers()) ::
  {:ok, response()} | {:error, error()} | no_return()
Link to this callback

request(method, url, headers, body)

View Source

Specs

request(method(), url(), headers(), body()) ::
  {:ok, response()} | {:error, error()} | no_return()
Link to this callback

request(method, url, headers, body, t)

View Source

Specs

request(method(), url(), headers(), body(), Keyword.t()) ::
  {:ok, response()} | {:error, error()} | no_return()