MikrotikApi.Transport behaviour (mikrotik_api v0.3.4)

View Source

Behaviour for pluggable MikroTik API transports.

The default transport is MikrotikApi.Transport.Httpc. Tests can use MikrotikApi.Transport.Mock to stub RouterOS REST endpoints without a device.

Custom transports must implement request/5 and return the same shape as Erlang :httpc responses after normalization:

{:ok, {status, response_headers, response_body}}
{:error, reason}

Summary

Types

body()

@type body() :: iodata() | :undefined

headers()

@type headers() :: [{charlist(), charlist()}]

method()

@type method() :: :get | :post | :put | :patch | :delete

resp_body()

@type resp_body() :: binary()

resp_headers()

@type resp_headers() :: [{charlist(), charlist()}]

status()

@type status() :: pos_integer()

url()

@type url() :: charlist()

Callbacks

request(method, url, headers, body, keyword)

@callback request(method(), url(), headers(), body(), keyword()) ::
  {:ok, {status(), resp_headers(), resp_body()}} | {:error, term()}