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/*"

Pattern -- compiled pattern handle; free with pattern-free

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

Since: v0.1.0 (typed as Pattern in v0.2.5)

defn

pattern-free

(pattern-free [pat : Pattern] :)

release a compiled pattern handle.

patPattern handle from router-compile, or null ((:: 0 :Pattern))

:void

(pattern-free p)

Since: v0.1.0 (typed as Pattern in v0.2.5; named router-free before

defn

router-match

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

test a compiled pattern against a request path.

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

Captures -- captures handle on match (free with captures-free), null (i.e. (:: 0 :Captures)) on no-match

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

Since: v0.1.0 (Captures return typed v0.2.1; pat typed Pattern v0.2.5)

defn

captures-get

(captures-get [caps : Captures 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

(Result cstr cstr) -- ok(value) if found, err("missing") otherwise

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

Since: v0.1.0 (typed as Result in 0.2.0)

defn

captures-count

(captures-count [caps : Captures] :)

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 : Captures] :)

release a captures handle.

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

:void

(captures-free caps)

Since: v0.1.0