WardrikHTTP.Routes (wardrik_http v0.1.0-rc.1)

Copy Markdown

Matches a request's method and path to an operation in WardrikProtocol's OpenAPI document.

Summary

Functions

Returns the operation for method and the decoded path segments, with its path parameters, or :error.

Functions

match(method, segments)

@spec match(String.t(), [String.t()]) ::
  {:ok, WardrikProtocol.operation(), %{required(String.t()) => String.t()}}
  | :error

Returns the operation for method and the decoded path segments, with its path parameters, or :error.

An agent ID takes two segments, or three if the second starts with @. A conversation follows it as conversations/ID.

WardrikHTTP.Routes.match("POST", ["v1", "agents", "acme", "@jon", "triage", "messages"])
#=> {:ok, %{id: "agent.ask", ...}, %{"agent" => "acme/@jon/triage"}}

WardrikHTTP.Routes.match("GET", ~w(v1 agents acme triage conversations C1 timeline))
#=> {:ok, %{id: "agent.timeline", ...}, %{"agent" => "acme/triage/C1"}}