peppermint v0.3.0 Peppermint View Source
Processless HTTP functions build on Mint.
Examples:
{:ok, response} = Peppermint.get("http://httpbin.org/")
{:ok, response} = Peppermint.post("http://httpbin.org/post", params: %{foo: "bar"})
Link to this section Summary
Request
Connect to the host, execute a request and disconnect.
Functions
Execute a request on a (Mint) connection. Response messages will be sent to the caller process
Handle a Mint message. Requires a map as accumulator which contains the requested request_ref's as keys and maps as values. Returns both the accumulator and any done responses.HTTP
Receive the response of a single request_req
Link to this section Types
Specs
request_error() :: {:error, Mint.Types.error() | :receive_timeout}
Link to this section Request
Specs
request(atom(), String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Connect to the host, execute a request and disconnect.
Link to this section Request Helpers
Specs
delete(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
get(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
head(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
options(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
patch(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
post(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
put(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Specs
trace(String.t(), keyword()) :: {:ok, Peppermint.Response.t()} | request_error()
Link to this section Functions
Specs
close(Mint.HTTP.t()) :: {:ok, Mint.HTTP.t()}
Specs
connect(String.t(), keyword()) :: {:ok, Mint.HTTP.t()} | {:error, Mint.Types.error()}
connect(URI.t(), keyword()) :: {:ok, Mint.HTTP.t()} | {:error, Mint.Types.error()}
Specs
connect(Mint.Types.scheme(), String.t(), :inet.port_number(), keyword()) :: {:ok, Mint.HTTP.t()} | {:error, Mint.Types.error()}
Specs
execute(Mint.HTTP.t(), atom(), String.t(), keyword()) :: {:ok, Mint.HTTP.t(), Mint.Types.request_ref()} | {:error, Mint.HTTP.t(), any()}
Execute a request on a (Mint) connection. Response messages will be sent to the caller process
Handle a Mint message. Requires a map as accumulator which contains the requested request_ref's as keys and maps as values. Returns both the accumulator and any done responses.HTTP
Can be used in a receive loop or for example in a GenServer.
{:ok, conn, request_ref} = Peppermint.request(conn, :get, "/")
acc = %{request_ref => %{}}
When receiving a message:
case handle_message(conn, message, acc) do
{:ok, conn, {acc, results}} ->
# check if your request_ref is in the results
{:error, conn, reason, results} ->
# error in the connection, you'd probably want to abort here
{:unknown, conn, acc} ->
# unknown message, use `Mint.HTTP.is_connection_message` to guard this from hapening
end
Receive the response of a single request_req