tourist/dsl
Route type and HTTP method constructors.
Since: v0.1.0
route-new
(route-new [method : cstr pat : int handler : int] :)
construct a Route from a compiled pattern handle.
| method | HTTP method string: "GET", "POST", "PUT", "DELETE", or "" | |
| for any-method matching | ||
| pat | compiled pattern handle from router-compile | |
| handler | Turmeric function value (fn [req :int] :int) |
:int -- Route handle; free with route-free (which also frees pat)
(route-new "GET" (router-compile "/hello") my-handler)
Since: v0.1.0
route-method
(route-method [r : int] :)
HTTP method string of a Route ("" means any).
| r | :int Route handle |
:cstr -- e.g. "GET", "POST", or "" for any
Since: v0.1.0
route-pattern
(route-pattern [r : int] :)
compiled pattern handle of a Route.
| r | :int Route handle |
:int -- compiled pattern handle (from router-compile)
Since: v0.1.0
route-handler
(route-handler [r : int] :)
raw handler function value of a Route.
| r | :int Route handle |
:int -- Turmeric function value; call via route-call-handler
Since: v0.1.0
route-call-handler
(route-call-handler [r : int req : int] :)
invoke a Route's handler with a request.
| r | :int Route handle | |
| req | :int Request handle (from httpd/request or tourist ctx) |
:int -- Response handle returned by the handler
(route-call-handler route req)
Since: v0.1.0
route-free
(route-free [r : int] :)
release a Route handle and its compiled pattern.
| r | :int Route handle, or 0 (no-op) |
:void
(route-free r)
Since: v0.1.0
get!
(get! [pattern : cstr handler : int] :)
declare a GET route.
| pattern | route pattern string, e.g. "/hello/:name" | |
| handler | (fn [req :int] :int) request handler |
:int -- Route handle; consumed by tourist
(get! "/hello/:name"
(fn [req] (text "hi")))
Since: v0.1.0
post!
(post! [pattern : cstr handler : int] :)
declare a POST route.
| pattern | route pattern string | |
| handler | (fn [req :int] :int) request handler |
:int -- Route handle
Since: v0.1.0
put!
(put! [pattern : cstr handler : int] :)
declare a PUT route.
| pattern | route pattern string | |
| handler | (fn [req :int] :int) request handler |
:int -- Route handle
Since: v0.1.0
delete!
(delete! [pattern : cstr handler : int] :)
declare a DELETE route.
| pattern | route pattern string | |
| handler | (fn [req :int] :int) request handler |
:int -- Route handle
Since: v0.1.0
any!
(any! [pattern : cstr handler : int] :)
declare a route matching any HTTP method.
| pattern | route pattern string | |
| handler | (fn [req :int] :int) request handler |
:int -- Route handle
(any! "/catch-all" (fn [req] (text "ok")))
Since: v0.1.0
Internal definitions
__route-alloc__route-free-struct