View Source Frugality (Frugality v0.1.0)

Link to this section Summary

Functions

Evaluates the request preconditions against user-provided data.

Stores the entity-tag encoder in the connection.

Stores the metadata generator in the connection.

Derives metadata and puts it in the response headers.

Short-circuits the connection when the preconditions are satisfied.

Link to this section Functions

Link to this function

evaluate_preconditions(conn, data)

View Source
@spec evaluate_preconditions(Plug.Conn.t(), map() | list()) ::
  {:ok | :error, Plug.Conn.t()}

Evaluates the request preconditions against user-provided data.

Returns {:ok, t:Plug.Conn.t/0} if the preconditions are satisfied and the action execution can continue, or {:error, t:Plug.Conn.t/0} otherwise.

examples

Examples

iex> evaluate_preconditions(conn, etag: ~s(W/"asd123"))
{:ok, %Plug.Conn{...}}

iex> evaluate_preconditions(conn, order: order)
{:error, %Plug.Conn{status: 412, ...}}
Link to this function

put_encoder(conn, encoder)

View Source
@spec put_encoder(Plug.Conn.t(), Frugality.Encoder.t()) :: Plug.Conn.t()

Stores the entity-tag encoder in the connection.

examples

Examples

Can be invoked as a function:

iex> put_encoder(conn, Frugality.Encoder.MD5)

or used as a plug:

plug :put_encoder, Frugality.Encoder.MD5
Link to this function

put_generator(conn, generator)

View Source
@spec put_generator(Plug.Conn.t(), Frugality.Generator.t()) :: Plug.Conn.t()

Stores the metadata generator in the connection.

examples

Examples

Can be invoked as a function:

# Let's imagine you have an HTTP document with orders
iex> put_generator(conn, OrderMetadata)

or used as a plug:

plug :put_generator, OrderMetadata
Link to this function

put_metadata(conn, data)

View Source
@spec put_metadata(Plug.Conn.t(), map() | list()) :: Plug.Conn.t() | no_return()

Derives metadata and puts it in the response headers.

examples

Examples

iex> conn = put_metadata(conn, order: order)
iex> Plug.Conn.get_resp_header(conn, "etag")
"W/\"asd123\""
Link to this function

short_circuit(conn, data, cb \\ fn conn -> conn end)

View Source
@spec short_circuit(Plug.Conn.t(), map() | list(), (Plug.Conn.t() -> Plug.Conn.t())) ::
  Plug.Conn.t()

Short-circuits the connection when the preconditions are satisfied.

To short-circuit the connection means to send it and halt the Plug pipeline.

examples

Examples

iex> short_circuit(conn, order: order)