ivar v0.2.0 Ivar

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

Summary

Functions

Creates a new request map for the given HTTP method and url

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

new(method, url)
new(atom, binary) :: map

Creates a new request map for the given HTTP method and url

Args

  • method - the HTTP method as an atom (:get, :post, :delete, etc…)
  • url - a binary containing the full url (e.g. https://example.com)

Usages

iex> Ivar.new(:get, "https://example.com")
%{method: :get, url: "https://example.com"}
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

send(request)
send(map) ::
  {:ok, HTTPoison.Response.t} |
  {:error, HTTPoison.Error.t}

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, %HTTPoison.Response{}}
unpack(response)
unpack(atom) ::
  {binary | map, HTTPoison.Response.t} |
  {:error, HTTPoison.Error.t}

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 - an HTTPoison success or failure response

Usage

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