http/response
src/http/response.tur
defn
response-status
(response-status [resp :int] :int)
HTTP status code of a response.
Parameters
| resp | :int response handle (unwrapped ok-val) |
Returns
:int -- HTTP status code (e.g. 200, 404)
Example
(response-status resp) ; => 200
Since: P5
defn
response-header
(response-header [resp :int name :cstr] :cstr)
look up a response header by name (case-insensitive).
Parameters
| resp | :int response handle | |
| name | header name, e.g. "Content-Type" |
Returns
:cstr -- header value, or "" if not found
Example
(response-header resp "Content-Type")
Since: P5
defn
response-body
(response-body [resp :int] :cstr)
raw body string of a response.
Parameters
| resp | :int response handle |
Returns
:cstr -- NUL-terminated response body
Example
(println (response-body resp))
Since: P5
defn
response-json
(response-json [resp :int] :ptr<void>)
parse the response body as JSON, returning a doc handle.
Parameters
| resp | :int response handle |
Returns
result<:int> -- ok(doc-handle) or err(:cstr message). Use json-emit / json-get-in from json/emit and json/patch to inspect.
Example
(let [jr (response-json resp)]
(when (ok? jr) (json-get-in (ok-val jr) "data.id")))
Since: P5