heimdall v0.4.1 Heimdall.DynamicRoutes

Module for dynamically registering routes and routing requests.

This is where most of the magic happens. All traffic through the application is routed through this plug.

Routes are stored in an ETS table to be looked up when the plug is called. When called Heimdall.DynamicRoutes search for a route that matches the request, wrap all plugs in the route into one function and call it with the current request. The final plug in the chain will always be Heimdall.Plug.ForwardRequest

Summary

Functions

Returns the route in given routes that matches a path as a list (which is how plug conns reperesent them internally). Will return :no_routes if no routes are found

Registers a route for later lookup

Unregisters a route given its host and path

Unregisters all routes for a give table

Functions

call(conn, tab)
init(list)
lookup_path(routes, conn_path)

Returns the route in given routes that matches a path as a list (which is how plug conns reperesent them internally). Will return :no_routes if no routes are found.

Examples

iex> Heimdall.DynamicRoutes.lookup_path([{"localhost", ["test", "path"], [], {}}], ["test", "path"])
{"localhost", ["test", "path"], [], {}}

iex> Heimdall.DynamicRoutes.lookup_path([{"localhost", ["test", "path"], [], {}}], ["test", "path", "but", "longer"])
{"localhost", ["test", "path"], [], {}}
register(tab, host, path, plugs, opts)

Registers a route for later lookup

unregister(tab, host, path)

Unregisters a route given its host and path

unregister_all(tab)

Unregisters all routes for a give table