Msgpax v2.2.4 Msgpax.PlugParser View Source

A Plug.Parsers plug for parsing a MessagePack-encoded body.

Look at the documentation for Plug.Parsers for more information on how to use Plug.Parsers.

This parser accepts the :unpacker option to configure how unpacking should be done. Its value can either be a module that implements the unpack!/1 function or a module, function, and arguments tuple. Note, the response body will be prepended to the given list of arguments before applying.

Examples

defmodule MyPlugPipeline do
  use Plug.Builder

  plug Plug.Parsers,
       parsers: [Msgpax.PlugParser],
       pass: ["application/msgpack"]

  # Or use the :unpacker option:
  plug Plug.Parsers,
       parsers: [Msgpax.PlugParser],
       pass: ["application/msgpack"],
       unpacker: {Msgpax, :unpack!, [[binary: true]]}

  # ... rest of the pipeline
end

Link to this section Summary

Functions

Callback implementation for Plug.Parsers.init/1

Attempts to parse the connection’s request body given the content-type type, subtype, and its parameters

Link to this section Functions

Callback implementation for Plug.Parsers.init/1.

Link to this function parse(conn, arg2, arg3, params, arg5) View Source

Attempts to parse the connection’s request body given the content-type type, subtype, and its parameters.

The arguments are:

  • the Plug.Conn connection
  • type, the content-type type (e.g., "x-sample" for the "x-sample/json" content-type)
  • subtype, the content-type subtype (e.g., "json" for the "x-sample/json" content-type)
  • params, the content-type parameters (e.g., %{"foo" => "bar"} for the "text/plain; foo=bar" content-type)

This function should return:

  • {:ok, body_params, conn} if the parser is able to handle the given content-type; body_params should be a map
  • {:next, conn} if the next parser should be invoked
  • {:error, :too_large, conn} if the request goes over the given limit

Callback implementation for Plug.Parsers.parse/5.