tourist/app
tourist entry point and server lifecycle.
Since: v0.1.0
tourist
(tourist [port : int items : int] :)
start an HTTP server on port with the given routes and middleware.
| port | TCP port to bind on (IPv4, INADDR_ANY) | |
| items | mix of Route and Middleware handles from the DSL constructors |
:ptr<void> -- server handle; pass to server-stop when done, or NULL on bind/pool failure
(import httpd/server :refer [server-stop])
(let [srv (tourist 3000
(use! logger)
(get! "/hello/:name"
(fn [req]
(text (ok-val (capture req "name"))))))]
(server-stop srv))
Since: v0.1.0
tourist-request-conn
(tourist-request-conn :)
the httpd Conn for the in-flight request.
Since: TOUR-V0
tourist-conn
(tourist-conn [port : int items : int] :)
like `tourist`, but on httpd's Conn-aware listener.
| port | TCP port to bind on. | |
| items | mix of Route and Middleware handles from the DSL constructors | |
| (including ws-route! from tourist-ws). |
:ptr<void> -- server handle; pass to server-stop when done, or NULL on bind/pool failure.
Since: TOUR-V0
TouristOpts
(defstruct TouristOpts [])
how tourist-with runs the server.
Since: tourist-on-stdlib-httpd H4
default-tourist-opts
(default-tourist-opts :)
`tourist`'s own settings: 8 workers, stdlib's
TouristOpts
(tourist-with 8080 (default-tourist-opts) (get! "/" home))
Since: tourist-on-stdlib-httpd H4
tourist-opts
(tourist-opts [^fat wrap : (fn [ptr<void>] ptr<void>)])
the default settings with a stdlib middleware stack.
| wrap | (fn [ptr<void>] ptr<void>), called once when the server starts |
TouristOpts
(tourist-with 8080
(tourist-opts (fn [inner : ptr<void>] : ptr<void>
(compose-middleware inner mw-log mw-recover
(mw-cors-opts cors))))
(get! "/" home))
Since: tourist-on-stdlib-httpd H4
tourist-with
(tourist-with [port : int opts : TouristOpts items : int] :)
like `tourist`, configured by a TouristOpts.
| port | TCP port to bind on (0 = kernel-assigned; see server-port) | |
| opts | TouristOpts | |
| items | mix of Route and Middleware handles from the DSL constructors |
:ptr<void> -- server handle for server-stop, or NULL on failure
(let [srv (tourist-with 8080
(tourist-opts (fn [inner : ptr<void>] : ptr<void>
(compose-middleware inner mw-log mw-recover)))
(get! "/" (fn [_] (text "hi"))))]
(server-stop srv))
Since: tourist-on-stdlib-httpd H4
tourist-conn-with
(tourist-conn-with [port : int opts : TouristOpts items : int] :)
like `tourist-conn`, configured by a TouristOpts.
| port | TCP port to bind on | |
| opts | TouristOpts | |
| items | mix of Route and Middleware handles (including ws-route!) |
:ptr<void> -- server handle for server-stop, or NULL on failure
Since: tourist-on-stdlib-httpd H4
Internal definitions
__tourist-cons-- allocate a cons cell carrying an Item head.__tourist-cons-head-- head Item of a cons cell.__tourist-cons-tail-- tail ItemList of a cons cell.__tourist-list-rev-- reverse an ItemList using an accumulator,__tourist-cell-free-- free one cons cell (not its head).__tourist-spine-free-- free the cells of a list, leaving the heads.tourist-state-ptr-- return a pointer to the persistent dispatch state.__tourist-state-set-- write mws, after_mws, and routes into dispatch state.__tourist-state-arounds-- read the use-around! list (declaration order).__tourist-state-mws-- read the mws cons list from the dispatch state.__tourist-state-after-mws-- read the after-mws cons list (reverse decl order).__tourist-state-routes-- read the routes cons list from the dispatch state.__tourist-collect-mws-- accumulate pre-middleware handles from items (reversed).__tourist-collect-after-mws-- accumulate after-middleware handles (reversed).__tourist-collect-arounds-- accumulate use-around! handles (reversed).__tourist-collect-routes-- accumulate route handles from items (reversed).__tourist-caps-wildcard-- extract the "*" wildcard value from captures.__tourist-method-match?-- true if rmethod matches the request method.__tourist-route-dispatch-- find the first matching route and dispatch.__tourist-ctx-swap-caps-- replace ctx->caps; return previous handle.__hdr-name-- resp-headers cons cell accessors.__hdr-value__hdr-next__apply-resp-headers-- walk ctx->resp_headers and append each to resp.__tourist-handler-- top-level request handler passed to server-start.__tourist-run-guarded-- __tourist-run, freeing the ctx when the request__tourist-run-- run the request through every use-around! (outermost__tourist-core-- the inside of every use-around!: the use! chain, then__tourist-around-next-- the `next` every use-around! receives.__tourist-handler-ptr-- return __tourist-handler as a typed (c-fn [int] int).__tourist-install-- sort the items into the dispatch state and free the__tourist-conn-cell-- thread-local current-request Conn slot.__tourist-handler-conn-- two-arg handler: record the Conn, then dispatch.__tourist-handler-conn-ptr-- __tourist-handler-conn as a (c-fn [int int] int).