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

Types

String case

t()

JSONAPIPlug context

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.

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"
Link to this function

render(conn, resource_or_resources \\ nil, links \\ nil, meta \\ nil, options \\ [])

View Source

Render JSON:API response

Renders the JSON:API response for the specified Resource.

Link to this function

url_for(resources, conn)

View Source
@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.

Link to this function

url_for_relationship(resource_or_resources, conn, relationship_type)

View Source

Generate relationships link

Generates the relationships link for a resource.