httpd/response
Response struct, constructors, and mutators.
Since: H4
with-header
(with-header [resp : int key : cstr val : cstr] :)
append a header to a Response (mutates in place).
| resp | :int Response handle | |
| key | header name | |
| val | header value |
:int -- the same Response handle (for chaining)
(-> (ok "text/plain" "hi")
(with-header "X-Hello" "world"))
Since: H4
with-body
(with-body [resp : int body : cstr] :)
replace the body of a Response (mutates in place).
| resp | :int Response handle | |
| body | new body string |
:int -- the same Response handle
(-> (ok "text/plain" "") (with-body "later"))
Since: H4
with-status
(with-status [resp : int status : int] :)
replace the status code of a Response (mutates in place).
| resp | :int Response handle | |
| status | new HTTP status code |
:int -- the same Response handle
(-> (ok "text/plain" "no") (with-status 503))
Since: H4
free-response
(free-response [resp : int] :)
release a Response handle and all owned storage.
| resp | :int Response handle, or 0 (no-op) |
:void
(free-response r)
Since: H4
response
(response [status : int content-type : cstr body : cstr] :)
build an HTTP response with an arbitrary status code.
| status | HTTP status code, e.g. 200, 201, 500 | |
| content-type | value for the Content-Type header, e.g. "text/html" | |
| body | response body string ("" for no body) |
:int -- Response handle. Free with free-response, or hand to the server which takes ownership on send.
(response 201 "application/json" "{\"id\":1}")
Since: H4
resp-ok
(resp-ok [content-type : cstr body : cstr] :)
build a 200 OK response.
| content-type | value for the Content-Type header | |
| body | response body string |
:int -- Response handle with status 200
(resp-ok "text/plain" "Hello, world!")
Since: H4
not-found
(not-found [body : cstr] :)
build a 404 Not Found response with a text/plain body.
| body | body string (typically a short message) |
:int -- Response handle with status 404
(not-found "no such resource")
Since: H4
bad-request
(bad-request [body : cstr] :)
build a 400 Bad Request response with a text/plain body.
| body | body string (typically a short error message) |
:int -- Response handle with status 400
(bad-request "missing id parameter")
Since: H4
Internal definitions
__resp-new