No matching definitions.

tourist/router

src/tourist/router.tur

route pattern compilation and request dispatch.

Since: v0.1.0

defn

router-compile

(router-compile [pattern : cstr] :)

compile a route pattern string into a match handle.

patternroute pattern string, e.g. "/user/:id" or "/files/*"

:int -- compiled pattern handle; free with router-free

(let [p (router-compile "/hello/:name")]
    (router-free p))

Since: v0.1.0

defn

router-free

(router-free [pat : int] :)

release a compiled pattern handle.

pat:int handle from router-compile, or 0 (no-op)

:void

(router-free p)

Since: v0.1.0

defn

router-match

(router-match [pat : int path : cstr] :)

test a compiled pattern against a request path.

pat:int compiled pattern from router-compile
pathrequest path string, e.g. "/user/42"

:int -- captures handle on match (free with captures-free), 0 on no-match

(let [caps (router-match p "/user/42")]
    (when (!= caps 0)
      (captures-get caps "id")))

Since: v0.1.0

defn

captures-get

(captures-get [caps : int key : cstr] :)

look up a capture by name.

caps:int captures handle from router-match
keycapture name, e.g. "id" for :id, or "*" for wildcard

:int -- result<:cstr>: ok(value) if found, err("missing") otherwise

(let [r (captures-get caps "id")]
    (when (ok? r) (ok-val r)))

Since: v0.1.0

defn

captures-count

(captures-count [caps : int] :)

number of captures in a captures handle.

caps:int captures handle from router-match

:int -- number of captured segments (0 for empty or null handle)

(captures-count caps)  ; => 1

Since: v0.1.0

defn

captures-free

(captures-free [caps : int] :)

release a captures handle.

caps:int handle from router-match, or 0 (no-op)

:void

(captures-free caps)

Since: v0.1.0