View Source CozyOSS.ApiClient behaviour (cozy_oss v0.2.0)

Specification for a CozyOSS API client.

It can be set to a client provided by CozyOSS, such as:

config :cozy_oss, :api_client, CozyOSS.ApiClient.Finch

Or, set it to your own API client, such as:

config :cozy_oss, :api_client, MyApiClient

Link to this section Summary

Types

The response of a request.

Callbacks

Callback to initialize the given API client.

Callback to send a request.

Functions

Send a struct %CozyOSS.ApiRequest{} as an HTTP request by the given API client.

Link to this section Types

@type body() :: binary() | map()
@type headers() :: [{binary(), binary()}]
@type response() :: {:ok, status(), headers(), body()} | {:error, term()}

The response of a request.

@type status() :: pos_integer()

Link to this section Callbacks

@callback init() :: :ok

Callback to initialize the given API client.

@callback request(CozyOSS.ApiRequest.t()) :: response()

Callback to send a request.

Link to this section Functions

@spec request(CozyOSS.ApiRequest.t()) :: response()

Send a struct %CozyOSS.ApiRequest{} as an HTTP request by the given API client.

When the Content-Type header of the response is "application/xml", this function will try to convert the XML content to a map with snaked-cased keys.