View Source JSONAPIPlug (jsonapi_plug v2.0.0)
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
Functions
JSON:API MIME type
Recase resource fields
Render JSON:API response
Generates the resource link
Generate relationships link
Types
@type case() :: :camelize | :dasherize | :underscore
String case
@type t() :: %JSONAPIPlug{ allowed_includes: keyword(keyword()), base_url: String.t(), config: Keyword.t(), fields: term(), filter: term(), include: term(), page: term(), params: Plug.Conn.params(), resource: JSONAPIPlug.Resource.t(), sort: term() }
JSONAPIPlug context
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"
render(conn, resource_or_resources \\ nil, links \\ nil, meta \\ nil, options \\ [])
View Source@spec render( Plug.Conn.t(), JSONAPIPlug.Resource.t() | [JSONAPIPlug.Resource.t()] | nil, JSONAPIPlug.Document.links() | nil, JSONAPIPlug.Document.meta() | nil, JSONAPIPlug.Resource.options() ) :: JSONAPIPlug.Document.t() | no_return()
Render JSON:API response
Renders the JSON:API response for the specified Resource.
@spec url_for( JSONAPIPlug.Resource.t() | [JSONAPIPlug.Resource.t()] | nil, Plug.Conn.t() | nil ) :: String.t()
Generates the resource link
Generates the resource link for a resource.
url_for_relationship(resource_or_resources, conn, relationship_type)
View Source@spec url_for_relationship( JSONAPIPlug.Resource.t() | [JSONAPIPlug.Resource.t()], Plug.Conn.t() | nil, JSONAPIPlug.Document.ResourceObject.type() ) :: String.t()
Generate relationships link
Generates the relationships link for a resource.