View Source JSONAPI.Deserializer (jsonapi v1.7.1)

This plug flattens incoming params for ease of use when casting to changesets. As a result, you are able to pattern match specific attributes in your controller actions.

Note that this Plug will only deserialize your payload when the request's content type is for a JSON:API request (i.e. "application/vnd.api+json"). All other content types will be ignored.

Example

For example these params:

%{
  "data" => %{
    "id" => "1",
    "type" => "user",
    "attributes" => %{
      "foo-bar" => true
    },
    "relationships" => %{
      "baz" => %{"data" => %{"id" => "2", "type" => "baz"}}
    }
  }
}

are transformed to:

%{
  "id" => "1",
  "type" => "user"
  "foo-bar" => true,
  "baz-id" => "2"
}

Usage

Just include in your plug stack after a json parser:

plug Plug.Parsers, parsers: [:json], json_decoder: Jason
plug JSONAPI.Deserializer

or a part of your Controller plug pipeline

plug JSONAPI.Deserializer

In addition, if you want to underscore your parameters

plug JSONAPI.Deserializer
plug JSONAPI.UnderscoreParameters

Summary

Functions