WardrikHTTP (wardrik_http v0.1.0-rc.1)

Copy Markdown

Serves Wardrik's operations over HTTP.

Most apps use Wardrik.HTTP, which sets :server and :sign_in for you:

children = [MyApp.AgentRuntime, {Wardrik.HTTP, wardrik: MyApp.AgentRuntime, port: 4000}]

Use WardrikHTTP directly to serve any Wardrik.Server:

children = [{WardrikHTTP, server: {Wardrik, MyApp.AgentRuntime}, port: 4000}]

It's also a Plug, so your router can forward a path to it.

Options

  • :server - required. {module, name}: the Wardrik.Server module, and the instance name it runs. Raises ArgumentError without it.
  • :authenticator - a WardrikHTTP.Authenticator, as {module, config}. {WardrikHTTP.Bearer, []} unless set.
  • :sign_in - {module, function, args} returning the {plug, opts} that serves sign-in pages, or nil. nil unless set.
  • :keepalive - milliseconds an idle event stream waits before sending a comment. 15_000.

As a child, it also takes Bandit's options, like :port and :ip.

Routes

RouteServes
each operation's routeevery operation in WardrikProtocol, as JSON
the same, with Accept: text/event-streamstreaming operations, as server-sent events
GET /v1/openapi.jsonthe OpenAPI document
GET /v1/workersthe tool workers' WebSocket. See WardrikHTTP.Worker.
POST /v1/channels/{channel}/{path}a chat app's request, relayed to the channel and back
/oauth/*sign-in pages, from :sign_in

GET /v1/workers returns 426 to a request with a valid token that isn't a WebSocket upgrade, so a worker can check its token first.

Every response has a request-id header. It's the caller's own if the request sent one.

Summary

Functions

Returns a child spec that serves with Bandit. Options not listed above go to Bandit.

Functions

child_spec(opts)

@spec child_spec(keyword()) :: Supervisor.child_spec()

Returns a child spec that serves with Bandit. Options not listed above go to Bandit.