Sake.Resource behaviour (Sake v0.1.0)

Copy Markdown View Source

A resource: a fixed uri: or a template with {name} placeholders, and read/2. A template resource may implement list/1 to enumerate concrete resources. subscribe: true lets clients subscribe to updates, which the host announces with Sake.Server.resource_updated/2.

Summary

Callbacks

complete(arg, partial, ctx)

(optional)
@callback complete(arg :: String.t(), partial :: String.t(), ctx :: Sake.Context.t()) ::
  {:ok, [String.t()]} | {:ok, [String.t()], keyword()}

list(ctx)

(optional)
@callback list(ctx :: Sake.Context.t()) :: [String.t() | map()]

read(params, ctx)

@callback read(params :: map(), ctx :: Sake.Context.t()) ::
  {:ok, term()} | {:error, :not_found} | {:error, String.t()}

spec()

@callback spec() :: Sake.Resource.Spec.t()