tourist/helpers
src/tourist/helpers.tur
response shorthand builders.
Since: v0.1.0
defn
text
(text [body : cstr] :)
build a 200 text/plain response.
Parameters
| body | response body string |
Returns
:int -- Response handle with status 200 and Content-Type text/plain
Example
(text "Hello, world!")
Since: v0.1.0
defn
html
(html [body : cstr] :)
build a 200 text/html response.
Parameters
| body | response body string (HTML markup) |
Returns
:int -- Response handle with status 200 and Content-Type text/html
Example
(html "<p>Hello</p>")
Since: v0.1.0
defn
json-body
(json-body [body : cstr] :)
build a 200 application/json response.
Parameters
| body | response body string (JSON-encoded value) |
Returns
:int -- Response handle with status 200 and Content-Type application/json
Example
(json-body "{\"ok\":true}")
Since: v0.1.0
defn
redirect
(redirect [path : cstr] :)
build a 302 redirect response.
Parameters
| path | target URL or path, e.g. "/new-path" |
Returns
:int -- Response handle with status 302 and Location header set
Example
(redirect "/new-path")
Since: v0.1.0
defn
status
(status [code : int resp : int] :)
override the HTTP status code of an existing response.
Parameters
| code | new HTTP status code, e.g. 201, 204, 422 | |
| resp | :int Response handle to modify |
Returns
:int -- the same Response handle with the updated status code
Example
(status 201 (text "created"))
Since: v0.1.0