March Docs

BastionRoutes

BastionRoutes: reversible routing helpers for Bastion web apps.

Provides a runtime route registry (backed by a Vault table) and helpers for building path strings with embedded segments and query parameters.

In the full compiler, routes would be auto-generated at compile time. This module provides the runtime half: path building, query encoding, and route introspection via BastionRoutes.all().

Typical usage:

-- Register routes at startup (the compiler does this automatically)
BastionRoutes.register("home", "get", "/", 0)
BastionRoutes.register("users", "get", "/users", 0)
BastionRoutes.register("user", "get", "/users/:id", 1)

-- Build paths (these would be typed helpers in the full compiler)
BastionRoutes.path("home", Nil, Nil)                          -- "/"
BastionRoutes.path("users", Nil, Nil)                         -- "/users"
BastionRoutes.path("user", Cons("42", Nil), Nil)              -- "/users/42"
BastionRoutes.path("users", Nil, Cons(("page","2"), Nil))     -- "/users?page=2"

Functions

fnallall()#

Retrieve all registered routes. Returns a list of route entries.

  BastionRoutes.all()
  -- => [("home", "get", "/", 0), ("user", "get", "/users/:id", 1), ...]
fnpathpath(name, segments, query)#

Build a path string for a named route, filling in path segments and appending query parameters.

name     — route name (must be registered)
segments — list of String values for dynamic path segments (in order)
query    — list of (String, String) query parameter pairs

  BastionRoutes.path("user", Cons("42", Nil), Nil)
  -- => "/users/42"

  BastionRoutes.path("users", Nil, Cons(("page", "2"), Nil))
  -- => "/users?page=2"

Returns "unknown route: <name>" if the route is not registered.

fnpath1path1(name, seg)#

Build a path with a single dynamic segment.

  BastionRoutes.path1("user", "42")  -- "/users/42"
fnpath2path2(name, seg1, seg2)#

Build a path with two dynamic segments.

  BastionRoutes.path2("post_comment", "10", "99")
  -- "/posts/10/comments/99"
fnregisterregister(name, method, pattern, arity)#

Register a named route in the global registry.

name    — string identifier, e.g. "user"
method  — HTTP method string: "get", "post", "put", "delete"
pattern — path pattern with :param segments: "/users/:id"
arity   — number of dynamic path segments (0 for static routes)

  BastionRoutes.register("user", "get", "/users/:id", 1)
fnstatic_pathstatic_path(name)#

Build a static path (no dynamic segments, no query params).

  BastionRoutes.static_path("home")  -- "/"