tourist/param
query-string parser and path-capture helpers.
Since: v0.1.0
tourist-ctx-caps
(tourist-ctx-caps [ctx : int] :)
raw __tourist_caps handle stored in a ctx.
| ctx | :int tourist context handle |
:int -- captures handle (may be 0)
Since: v0.1.0
tourist-ctx-strip-path
(tourist-ctx-strip-path [ctx : int new-path : cstr] :)
swap ctx->path with new-path and return the old.
| ctx | :int tourist ctx handle | |
| new-path | :cstr new value for ctx->path |
:cstr -- previous ctx->path value; pass it back in to restore.
Since: v0.2.0
req-full-path
(req-full-path [ctx : int] :)
original request path before any url-map! stripping.
| ctx | :int tourist ctx handle |
:cstr -- the original (unstripped) request path
;; Request: GET /api/users ;; sub-app mounted at /api (req-path ctx) ;; => "/users" (req-full-path ctx) ;; => "/api/users"
Since: v0.2.0
tourist-ctx-new
(tourist-ctx-new [req : int caps : int] :)
wrap an httpd request + captures into a tourist ctx.
| req | :int httpd request handle (caller retains ownership) | |
| caps | :int captures handle from router-match (ctx takes ownership) |
:int -- tourist ctx handle; free with tourist-ctx-free
(let [ctx (tourist-ctx-new req caps)]
...)
Since: v0.1.0
tourist-ctx-free
(tourist-ctx-free [ctx : int] :)
release a tourist ctx and its owned resources.
| ctx | :int tourist ctx handle, or 0 (no-op) |
:void
(tourist-ctx-free ctx)
Since: v0.1.0
param
(param [ctx : int key : cstr] :)
look up a query parameter by key.
| ctx | :int tourist ctx handle (from tourist-ctx-new or passed by app) | |
| key | query parameter name, e.g. "q" for ?q=hello |
:int -- result<:cstr>: ok(value) if found, err("missing") otherwise
(let [r (param req "q")]
(when (ok? r) (ok-val r)))
Since: v0.1.0
capture
(capture [ctx : int name : cstr] :)
look up a path-segment capture by name.
| ctx | :int tourist ctx handle | |
| name | capture name, e.g. "id" for ":id", or "*" for wildcard |
:int -- result<:cstr>: ok(value) if found, err("missing") otherwise
(let [r (capture req "name")]
(when (ok? r) (ok-val r)))
Since: v0.1.0
Internal definitions
__parse-qp-- parse a raw query string into parallel key/value arrays.__tourist-ctx-alloc__ctx-free-qp__ctx-free-struct