View Source JSONAPIPlug.API (jsonapi_plug v2.0.0)
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
end
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.
Summary
Functions
Retrieve API configuration
Types
@type options() :: keyword()
API configuration options:
:case
- This option controls how your API's field names will be cased. The currentJSON:API Specification v1.0
recommends dasherizing (e.g."favorite-color": "blue"
), while the upcomingJSON: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 isfalse
.: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", passnamespace: "api/v1"
.:normalizer
(atom/0
) - Normalizer for transformation ofJSON:API
document to and from user data. The default value isJSONAPIPlug.Normalizer.Ecto
.:query_parsers
(keyword/0
) - Parsers for transformation ofJSON: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]
.:fields
(atom/0
) - Fields query parameter parser. The default value isJSONAPIPlug.QueryParser.Ecto.Fields
.:filter
(atom/0
) - Filter query parameter parser. The default value isJSONAPIPlug.QueryParser.Filter
.:include
(atom/0
) - Include query parameter parser. The default value isJSONAPIPlug.QueryParser.Ecto.Include
.:page
(atom/0
) - Page query parameter parser. The default value isJSONAPIPlug.QueryParser.Page
.:sort
(atom/0
) - Sort query parameter parser. The default value isJSONAPIPlug.QueryParser.Ecto.Sort
.
:pagination
(atom/0
) - A module adopting theJSONAPIPlug.Pagination
behaviour for pagination. The default value isnil
.: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()
Functions
Retrieve API configuration
Please note that API configuration is also cached on first request and read back from it afterwards.