Simple Elixir HTTP client build on Mint. It supports both HTTP/1 and HTTP/2 requests.
Peppermint aims to provide a simple interface build on the modern low-level Mint library. It provides a pool-less architecture, but it can be used to build your own connection pools easily.
Currently peppermint requires elixir ~> 1.10
Add to your mix.exs and run mix deps.get:
def deps do
[
{:peppermint, "~> 0.3.0"},
{:castore, "~> 0.1.0"}
]
endFire a one-off request. Connects to the host, executes the request and disconnects.
{:ok, %{status: 200, headers: headers, body: body}} =
Peppermint.get("http://httpbin.org/get?foo=bar"){:ok, %{status: 200, headers: headers, body: body}} =
Peppermint.get("http://httpbin.org/get", params: %{foo: "bar"}){:ok, %{status: 200, headers: headers, body: body}} =
Peppermint.post("http://httpbin.org/post", params: %{foo: "bar"}){:ok, %{status: 200, headers: headers, body: body}} =
Peppermint.post("http://httpbin.org/post",
headers: [{"Content-Type", "application/json"}],
body: Jason.encode!(%{foo: "bar"})
)put, patch, delete, head, options and trace
transport_options: See mint docs - Thetimeouthere specifies the connect timeout (defaults to30_000)receive_timeout- Trigger timeout if no data received for x ms (defaults to5_000)
Peppermint.get("http://httpbin.org/get",
receive_timeout: 1_000,
transport_options: [timeout: 5_000]
)To reuse a connection, the Peppermint.Connection provides a simple GenServer to handle a connection and
simultanious requests over HTTP/2 (multiplexing) or sequentially over HTTP/1:
{:ok, conn} = Peppermint.Connection.open("http://httpbin.org")
{:ok, response} = Peppermint.Connection.request(conn, :get, "/get?foo=bar")
{:ok, response} = Peppermint.Connection.request(conn, :post, "/post", params: %{foo: "bar"})
:ok = Peppermint.Connection.close(conn)