hecate_plugin_cowboy (hecate_sdk v0.6.2)

View Source

Cowboy route setup helper for plugins.

Takes routes from a plugin's routes/0 callback and prepends the standard /plugin/{name}/ prefix.

Summary

Functions

Build a cowboy dispatch table for a plugin. Includes API routes and static file serving.

Prefix plugin routes with /plugin/{name}/api. Plugin routes are relative (e.g., "/documents/:id"). This prepends the standard prefix.

Standard WebSocket upgrade for plugin handlers. Call from a cowboy handler's init/2 to upgrade to WebSocket.

Functions

make_dispatch(PluginName, Routes)

-spec make_dispatch(PluginName :: string() | binary(), Routes :: [{string(), module(), term()}]) ->
                       cowboy_router:dispatch_rules().

Build a cowboy dispatch table for a plugin. Includes API routes and static file serving.

prefix_routes(PluginName, Routes)

-spec prefix_routes(PluginName :: string() | binary(), Routes :: [{string(), module(), term()}]) ->
                       [{string(), module(), term()}].

Prefix plugin routes with /plugin/{name}/api. Plugin routes are relative (e.g., "/documents/:id"). This prepends the standard prefix.

ws_upgrade(Req, State, Opts)

-spec ws_upgrade(Req :: cowboy_req:req(), State :: term(), Opts :: map()) ->
                    {cowboy_websocket, cowboy_req:req(), term()}.

Standard WebSocket upgrade for plugin handlers. Call from a cowboy handler's init/2 to upgrade to WebSocket.