View Source JSONAPIPlug (jsonapi_plug v1.0.4)
JSONAPIPlug context
This defines a struct for storing configuration and request data. JSONAPIPlug.Plug
populates
its attributes by means of a number of other plug modules used to parse and validate requests
and stores it in the Plug.Conn
private assings under the jsonapi_plug
key.
Summary
Types
@type case() :: :camelize | :dasherize | :underscore
@type t() :: %JSONAPIPlug{ api: JSONAPIPlug.API.t(), fields: term(), filter: term(), include: term(), page: term(), params: Plug.Conn.params(), resource: JSONAPIPlug.Resource.t(), sort: term() }
Functions
@spec mime_type() :: String.t()
JSON:API MIME type
Returns the JSON:API MIME type.
@spec recase(JSONAPIPlug.Resource.field_name() | String.t(), case()) :: String.t()
Recase resource fields
Changes the case of resource field names to the specified case, ignoring underscores or dashes that are not between letters/numbers.
Examples
iex> recase("top_posts", :camelize)
"topPosts"
iex> recase(:top_posts, :camelize)
"topPosts"
iex> recase("_top_posts", :camelize)
"_topPosts"
iex> recase("_top__posts_", :camelize)
"_top__posts_"
iex> recase("", :camelize)
""
iex> recase("top_posts", :dasherize)
"top-posts"
iex> recase("_top_posts", :dasherize)
"_top-posts"
iex> recase("_top__posts_", :dasherize)
"_top__posts_"
iex> recase("top-posts", :underscore)
"top_posts"
iex> recase(:top_posts, :underscore)
"top_posts"
iex> recase("-top-posts", :underscore)
"-top_posts"
iex> recase("-top--posts-", :underscore)
"-top--posts-"
iex> recase("corgiAge", :underscore)
"corgi_age"