Ankusa.SDK.Routes (ankusa_sdk v0.6.0)

Copy Markdown View Source

The route-management listener (routes.admin.port, default 4003): the route table the edge enforces, plus the global IP rules and a dry run that replays the guard's decision.

The listener performs no authentication of its own — :headers is for whatever a deployer's boundary (a service mesh, an API gateway) expects in front of it.

Route ids are percent-encoded as one path segment, so /, ?, # and % in an id cannot reshape the URL; an id that isn't a string, is empty, or is ./.. is refused with Ankusa.SDK.InvalidRouteIdError before any request is sent.

Failures carry retryable, so a caller needs one bit to decide whether to try again or surface the rejection:

ErrorretryableCause
Ankusa.SDK.InvalidRouteIdErrorfalseunusable id, caught before the request
Ankusa.SDK.RouteNotFoundErrorfalse404
Ankusa.SDK.RoutesRejectedErrorfalseany other 4xx
Ankusa.SDK.RoutesUnavailableErrortrue5xx, a redirect, a non-JSON body, or unreachable
routes = Ankusa.SDK.Routes.new("http://localhost:4003")
{:ok, page} = Ankusa.SDK.Routes.list_routes(routes, enabled: true, limit: 10)

Summary

Functions

Store a route: POST /admin/routes → the route, timestamps included.

Delete a route: DELETE /admin/routes/{id}.

The global IP rules: GET /admin/ip-rules.

Fetch one route: GET /admin/routes/{id}.

Liveness probe: GET /health → {"status", "routes"}.

A page of route definitions: GET /admin/routes.

Build a client for base_url.

Replace the global IP rules: PUT /admin/ip-rules.

Replace a route: PUT /admin/routes/{id}.

The dry-run decision for one request: POST /admin/routes/test.

Patch a route: PATCH /admin/routes/{id}.

Types

t()

@type t() :: %Ankusa.SDK.Routes{http: term()}

Functions

create_route(client, input)

@spec create_route(t(), map()) :: {:ok, term()} | {:error, Exception.t()}

Store a route: POST /admin/routes → the route, timestamps included.

delete_route(client, id)

@spec delete_route(t(), term()) :: :ok | {:error, Exception.t()}

Delete a route: DELETE /admin/routes/{id}.

Returns :ok on 2xx; the body is not parsed (204 carries none).

get_ip_rules(client)

@spec get_ip_rules(t()) :: {:ok, term()} | {:error, Exception.t()}

The global IP rules: GET /admin/ip-rules.

get_route(client, id)

@spec get_route(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

Fetch one route: GET /admin/routes/{id}.

health(client)

@spec health(t()) :: {:ok, term()} | {:error, Exception.t()}

Liveness probe: GET /health → {"status", "routes"}.

list_routes(client, params \\ [])

@spec list_routes(t(), term()) :: {:ok, term()} | {:error, Exception.t()}

A page of route definitions: GET /admin/routes.

params may carry enabled, limit and cursor; nil values are left out of the query string rather than sent as =.

new(base_url, opts \\ [])

@spec new(String.t(), keyword()) :: t()

Build a client for base_url.

Options are :headers (a map or {name, value} list sent on every request), :timeout_ms (default 10_000, applied to connect and receive — to receive only with a :finch pool, which owns its connect options), and :req_options (transport tuning: :finch, :connect_options, :pool_timeout, :plug; :finch and :connect_options are exclusive).

put_ip_rules(client, rules)

@spec put_ip_rules(t(), map()) :: {:ok, term()} | {:error, Exception.t()}

Replace the global IP rules: PUT /admin/ip-rules.

replace_route(client, id, input)

@spec replace_route(t(), term(), map()) :: {:ok, term()} | {:error, Exception.t()}

Replace a route: PUT /admin/routes/{id}.

test_route(client, request)

@spec test_route(t(), map()) :: {:ok, term()} | {:error, Exception.t()}

The dry-run decision for one request: POST /admin/routes/test.

Nothing is captured; the response replays what the guard would have decided.

update_route(client, id, patch)

@spec update_route(t(), term(), map()) :: {:ok, term()} | {:error, Exception.t()}

Patch a route: PATCH /admin/routes/{id}.