Packages

Quickly create API clients using module attributes.

Current section

Files

Jump to
exrequester lib http_bin_sample.ex
Raw

lib/http_bin_sample.ex

defmodule HTTPBinSample do
use EXRequester
@get "/status"
@headers [
Authorization: :auth,
]
defreq get_status do
response.headers |> IO.inspect
end
end
defmodule Mix.Tasks.MyTask do
use Mix.Task
use EXRequester
@shortdoc "do stuff"
def run(_) do
HTTPBinSample.client("http://httpbin.org")
|> HTTPBinSample.get_status(auth: "123")
# HTTPBinSample.client("http://localhost:9090/")
# |> HTTPBinSample.some_request(auth: "password", key1: "The_value")
#
# HTTPBinSample.client("http://localhost:9090/")
# |> HTTPBinSample.request_with_body(body: "Hello World")
#
# HTTPBinSample.client("https://httpbin.org")
# |> HTTPBinSample.get_resource(sort: "ascending", filter: ["all", "2"])
#
# HTTPBinSample.client("http://localhost:9090/")
# |> HTTPBinSample.request_with_body(body: %{key1: "value1", key2: "value2"},
# decoder: &(&1.body |> Poison.decode! |> Map.get("Hello"))) |> IO.inspect
end
end