No matching definitions.

tourist/routing

src/tourist/routing.tur

url-map! and cascade! routing combinators.

Since: v0.2.0

defn

mount!

(mount! [prefix : cstr item : int] :)

build a (prefix, sub-app) mount entry for url-map!.

prefix:cstr path prefix, e.g. "/api" or "/" (catch-all)
item:int handle of a Route (from get!/post!/...) or sub-app
(from url-map!/cascade!)

:int -- opaque mount handle; pass to url-map!.

(url-map! (mount! "/api"   api-routes)
            (mount! "/admin" admin-app)
            (mount! "/"      public-app))

Since: v0.2.0

defn

subapp-item?

(subapp-item? [item : int] :)

true if an item handle is a sub-app (vs. a Route).

item:int item handle

:bool

Since: v0.2.0

defn

subapp-call

(subapp-call [item : int ctx : int] :)

dispatch a sub-app on a tourist ctx.

item:int sub-app handle (created by url-map!/cascade!)
ctx:int tourist ctx

:int -- response handle on hit, or 0 on no match

Since: v0.2.0

defn

url-map!

(url-map! [mounts : int] :)

mount sub-apps at path prefixes (longest-prefix-first).

& mounts :int -- one or more handles from mount!

:int -- sub-app handle; consumed by tourist or by an outer url-map!/cascade!.

(tourist 3000
    (url-map! (mount! "/api"   (api-routes))
              (mount! "/admin" (admin-app))
              (mount! "/"      (get! "/" (fn [_] (text "home"))))))

Since: v0.2.0

defn

cascade!

(cascade! [apps : int] :)

try apps in order; pass on 404/405 to the next.

& apps :int -- handlers to try in order

:int -- sub-app handle

(tourist 3000
    (cascade! (get! "/about" (fn [_] (text "About")))
              (serve-static! "/" "./public")))

Since: v0.2.0

defn

passes!

(passes! [statuses : int] :)

build a pass-through status list for cascade-with!.

& statuses :int -- one or more HTTP status codes to treat as fall-through

:int -- opaque status-list handle; pass to cascade-with!.

(cascade-with! (passes! 404 405 503) primary fallback)

Since: v0.2.0

defn

cascade-with!

(cascade-with! [passes : int apps : int] :)

cascade with a custom pass-through status list.

passes :int -- status-list handle from passes!
& apps :int -- handlers to try in order

:int -- sub-app handle

;; Also pass through 503 (maintenance mode of first app)
  (cascade-with! (passes! 404 405 503) primary fallback)

Since: v0.2.0

Internal definitions
__rt-cons
__rt-cons-head
__rt-cons-tail
__mount-prefix-len
__mount-prefix
__mount-item
__subapp-alloc
__subapp-tag
__subapp-data
__prefix-match?-- true if path begins with prefix at a segment boundary.
__stripped-path-- pointer into path after stripping a matched prefix.
__method-match?-- "" matches any method; otherwise strcmp.
__ctx-method-- read method field from a tourist ctx (or httpd req).
__ctx-path-- read current (possibly stripped) path from ctx.
__ctx-set-caps-- replace ctx->caps with caps, returning the previous.
__dispatch-item-- dispatch a single item (Route or sub-app) on ctx.
__url-map-dispatch-- walk sorted mount list and dispatch first match.
__cascade-alloc
__cascade-passes
__cascade-apps
__resp-status-- read status field from a response handle.
__status-in?-- true if status appears in the int cons list passes.
__free-response-- release a response handle.
__cascade-dispatch-- run apps in order; check status against passes.
__insert-sorted-- insert mount m into a longest-prefix-first cons list.
__build-mounts-- consume the variadic cons list of mount handles and
__default-passes-- cons list {404, 405} (allocated once per call site).