ex_api v1.0.0-rc.2 ExApi.Implementation View Source

Defines struct for api implementation and macro to create it.

import ExApi.Implementation
def_api_impl MyLibrary.Api, :impl_id do
  # api implementation contents here ...
end

Link to this section Summary

Functions

Defines an api implementation. api implementation implements as much features as possible. You can preview on api implementation extra doc pages which features are supported, not supported or simply not implemented yet

Link to this section Types

Link to this type t() View Source
t() :: %ExApi.Implementation{api: module, doc: String.t, features: %{optional({funtion_name :: atom, arity :: non_neg_integer}) => :suported | :not_supported | :not_implemented}, group: atom, id: atom, line: non_neg_integer, module: module}

Link to this section Functions

Link to this macro def_api_impl(api, id, name \\ nil, line \\ nil, opts) View Source (macro)
def_api_impl(term, module, atom, module, non_neg_integer, Keyword.t) :: {:module, module, binary, term}

Defines an api implementation. api implementation implements as much features as possible. You can preview on api implementation extra doc pages which features are supported, not supported or simply not implemented yet.

Note: Don’t set manually line argument. It’s used internally when defining implementation inside api.

Attributes

  1. @moduledoc - defines documentation for api implementation.
  2. @impl_group - name of implementations group (default: nil)

Example:

def_api_impl MyApi, :my_id do
  @moduledoc """
  Describe what you are implementing for this api.
  For example you can implement api to use specific 3rd-party service.
  Also you can describe a configuration that will be used by your implementation.
  In this case you can for example allow to optionally change remote host and/or port.
  """

  def_feature_impl feature_name(data), do: to_string(data)

  def_no_support :another_feature_name, 1
end

You can define api implementation in three ways:

  1. By specifing only id of api implementation.
def_api_impl MyApi, :my_id do
  # ...
end
  1. By specifing id and module of api implementation, like:
def_api_impl MyApi, :my_id, MyApi.MyId do
  # ...
end
  1. Inside api:
def_api MyApi do
  # api contents here ...

  def_impl :my_id do
    # implementation content goes here ...
  end
end

All examples above defines same implementation with module name MyApi.MyId and id :my_id for MyApi api.