View Source JSONAPIPlug.API (jsonapi_plug v1.0.6)

JSON:API API Configuration

You can define an API by "use-ing" JSONAPIPlug.API in your API module:

  defmodule MyApp.API do
    use JSONAPIPlug.API, otp_app: :my_app

API module configuration can be customized via your application configuration:

  config :my_app, MyApp.API,
    namespace: "api",
    case: :dasherize

See options/0 for all available configuration options.



API configuration options



Retrieve a configuration option


@type options() :: keyword()

API configuration options:

  • :case - This option controls how your API's field names will be cased. The current JSON:API Specification v1.0 recommends dasherizing (e.g. "favorite-color": "blue"), while the upcoming JSON:API Specification v1.1 recommends camelCase (e.g. "favoriteColor": "blue"). The default value is :camelize.

  • :client_generated_ids (boolean/0) - Enable support for Client-Generated IDs. When enabled, the resources received in requests are supposed to contain a valid 'id'. The default value is false.

  • :links (boolean/0) - Enable link generation. The default value is true.

  • :host (String.t/0) - Hostname used for link generation instead of deriving it from the connection.

  • :namespace (String.t/0) - Namespace for all resources in your API. if you want your resources to live under ".../api/v1", pass namespace: "api/v1".

  • :normalizer (atom/0) - Normalizer for transformation of JSON:API document to and from user data. The default value is JSONAPIPlug.Normalizer.Ecto.

  • :query_parsers (keyword/0) - Parsers for transformation of JSON:API request query parameters to user data. The default value is [fields: JSONAPIPlug.QueryParser.Ecto.Fields, filter: JSONAPIPlug.QueryParser.Filter, include: JSONAPIPlug.QueryParser.Ecto.Include, page: JSONAPIPlug.QueryParser.Page, sort: JSONAPIPlug.QueryParser.Ecto.Sort].

  • :pagination (atom/0) - A module adopting the JSONAPIPlug.Pagination behaviour for pagination. The default value is nil.

  • :port (pos_integer/0) - Port used for link generation instead of deriving it from the connection.

  • :scheme - Scheme used for link generation instead of deriving it from the connection.

  • :version - JSON:API version advertised in the document The default value is :"1.0".

@type t() :: module()


Link to this function

get_config(api, path, default \\ nil)

View Source
@spec get_config(t() | nil, [atom()], term()) :: term()

Retrieve a configuration option

Retrieves an API configuration option value, with fallback to a default value in case the configuration option is not present.