ivar v0.10.1 Ivar

Ivar is the top level module used to compose HTTP requests.

Summary

Functions

Calls Ivar.new/3 with the method set to :delete for the given url and opts

Calls Ivar.new/3 with the method set to :get for the given url and opts

Creates a new request map for the given HTTP method and url and merges the specified opts into the application level options defined in the config.exs

Calls Ivar.new/3 with the method set to :patch for the given url and opts

Calls Ivar.new/3 with the method set to :post for the given url and opts

Calls Ivar.new/3 with the method set to :put for the given url and opts

Sends the given HTTP request

Receives the result of Ivar.send/1 and attempts to decode the response body using the content-type header included in the HTTP response

Functions

delete(url, opts \\ [])
delete(binary, Keyword.t) :: map

Calls Ivar.new/3 with the method set to :delete for the given url and opts

Args

  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.delete("https://example.com", [timeout: 10_000])
%{method: :delete, url: "https://example.com", opts: [timeout: 10_000]}
get(url, opts \\ [])
get(binary, Keyword.t) :: map

Calls Ivar.new/3 with the method set to :get for the given url and opts

Args

  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.get("https://example.com", [timeout: 10_000])
%{method: :get, url: "https://example.com", opts: [timeout: 10_000]}
new(method, url, opts \\ [])
new(atom, binary, Keyword.t) :: map

Creates a new request map for the given HTTP method and url and merges the specified opts into the application level options defined in the config.exs

Args

  • method - the HTTP method as an atom (:get, :post, :delete, etc…)
  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.new(:get, "https://example.com", [timeout: 10_000])
%{method: :get, url: "https://example.com", opts: [timeout: 10_000]}
patch(url, opts \\ [])
patch(binary, Keyword.t) :: map

Calls Ivar.new/3 with the method set to :patch for the given url and opts

Args

  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.patch("https://example.com", [timeout: 10_000])
%{method: :patch, url: "https://example.com", opts: [timeout: 10_000]}
post(url, opts \\ [])
post(binary, Keyword.t) :: map

Calls Ivar.new/3 with the method set to :post for the given url and opts

Args

  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.post("https://example.com", [timeout: 10_000])
%{method: :post, url: "https://example.com", opts: [timeout: 10_000]}
put(url, opts \\ [])
put(binary, Keyword.t) :: map

Calls Ivar.new/3 with the method set to :put for the given url and opts

Args

  • url - a binary containing the full url (e.g. https://example.com)
  • opts - keyword list containing any valid options for the configured http adapater

Usages

Ivar.put("https://example.com", [timeout: 10_000])
%{method: :put, url: "https://example.com", opts: [timeout: 10_000]}
put_auth(request, credentials, auth_type)
put_auth(map, {tuple | binary}, atom) :: map

Delegates to Ivar.Auth.put/3

put_body(request, content, content_type)
put_body(map, {map | list | binary}, atom | binary) :: map

Delegates to Ivar.Body.put/3

put_files(request, files)
put_files(map, {tuple | list}) :: map | {:error, binary}

Delegates to Ivar.Files.put/2

put_headers(request, headers)
put_headers(map, {tuple | Keyword.t | map}) :: map

Delegates to Ivar.Headers.put/2

put_query_string(request, params)
put_query_string(map, list | Keyword.t | map) ::
  map |
  {:error, binary}

Delegates to Ivar.QueryString.put/2

send(request)
send(map) :: {:ok, map} | {:error, binary | atom}

Sends the given HTTP request

Args

  • request - the map containing the request options to send, usually created via Ivar.new/2

Usage

Ivar.new(:get, "https://example.com")
|> Ivar.send
# {:ok, %{status_code: 200, body: "", ...}}
unpack(response)
unpack(tuple) ::
  {binary | map, map} |
  {:error, binary | atom}

Receives the result of Ivar.send/1 and attempts to decode the response body using the content-type header included in the HTTP response

Args

  • response - a map containing the request response, usually the result of Ivar.send/1

Usage

Ivar.new(:get, "https://example.com")
|> Ivar.send
|> Ivar.unpack
# {"<!doctype html><html>...", %{status_code: 200, ...}}