mojito v0.2.0 Mojito.Pool View Source

Mojito.Pool provides an HTTP 1.x request connection pool based on Mojito and Poolboy.

Example:

>>>> children = [Mojito.Pool.child_spec(MyPool)]
>>>> {:ok, _pid} = Supervisor.start_link(children, strategy: :one_for_one)
>>>> Mojito.Pool.request(MyPool, :get, "http://example.com")
{:ok, %Mojito.Response{...}}

Link to this section Summary

Functions

Returns a child spec suitable to pass to e.g., Supervisor.start_link/2

Makes an HTTP 1.x request using an existing connection pool

Link to this section Functions

Link to this function

child_spec(name, opts \\ []) View Source

Returns a child spec suitable to pass to e.g., Supervisor.start_link/2.

Options:

  • :size sets the initial pool size. Default is 10.
  • :max_overflow sets the maximum number of additional connections under high load. Default is 5.
  • :strategy sets the pool connection-grabbing strategy. Valid values are :fifo and :lifo (default).

The :size and :max_overflow options are passed to Poolboy.

Link to this function

request(pool, method, url, headers \\ [], payload \\ "", opts \\ []) View Source
request(
  pid(),
  Mojito.method(),
  String.t(),
  Mojito.headers(),
  String.t(),
  Keyword.t()
) :: {:ok, Mojito.response()} | {:error, Mojito.error()}

Makes an HTTP 1.x request using an existing connection pool.

Options:

  • :timeout - Response timeout in milliseconds. Defaults to Application.get_env(:mojito, :request_timeout, 5000).