multiverse v2.0.0 Multiverse.Adapters.ISODate

Adapter that fetches ISO-8601 date from request header and Elixir.Date to resolve changes that must be applied to the connection.

This adapter requires you to configure which version is used by default, when value in a header was malformed or not set. It’s configured via :default_version, supported values:

  • :first - apply all gates by default. This option is useful when you integrate Multiverse in existing project and API consumers are not ready to accept latest changes by default;
  • :latest - user current date as default version. This option is useful when there are no legacy clients or there was no breaking changes before those clients started to send API version.

Version Channels

Consumers can use two channels instead of date in version header:

  • latest - apply only changes scheduled for future (with a date later than date when request arrived);
  • edge - do not apply any changes.

Link to this section Summary

Functions

Fetch default client version

Initializes adapter configuration at compile time

Resolve version by string value from request header

Comparator that is used to order and filter versions that should be applied to a connection

Link to this section Functions

Link to this function fetch_default_version(conn, adapter_config)
fetch_default_version(
  conn :: Plug.Conn.t(),
  adapter_config :: Multiverse.Adapter.config()
) :: {:ok, version(), Plug.Conn.t()}

Fetch default client version.

This callback is used when version header is not set or empty. Additionally adapters may use it to fallback to default version in case of errors or when version header value is malformed.

Callback implementation for Multiverse.Adapter.fetch_default_version/2.

Link to this function init(adapter, opts)

Initializes adapter configuration at compile time.

Raises when :default_version option is not set.

Link to this function resolve_version_or_channel(conn, version, adapter_config)
resolve_version_or_channel(
  conn :: Plug.Conn.t(),
  channel_or_version :: String.t(),
  adapter_config :: Multiverse.Adapter.config()
) :: {:ok, version(), Plug.Conn.t()}

Resolve version by string value from request header.

This callback can be used to set named channels for API versions, for eg. latest header value could be resolved to current date and edge to the most recent defined version.

Also, it is responsible for casting string value to adapter-specific version type and handling possible errors.

You can terminate connection if you want to return error without further processing of the request.

Callback implementation for Multiverse.Adapter.resolve_version_or_channel/3.

Link to this function version_comparator(v1, v2)
version_comparator(v1 :: version(), v2 :: version()) :: boolean()

Comparator that is used to order and filter versions that should be applied to a connection.

It should compare two arguments, and return true if the first argument precedes the second one or they are equal.

Callback implementation for Multiverse.Adapter.version_comparator/2.