No matching definitions.

httpd/response

src/httpd/response.tur

Response struct, constructors, and mutators.

Since: H4

defn

with-header

(with-header [resp : int key : cstr val : cstr] :)

append a header to a Response (mutates in place).

resp:int Response handle
keyheader name
valheader value

:int -- the same Response handle (for chaining)

(-> (ok "text/plain" "hi")
      (with-header "X-Hello" "world"))

Since: H4

defn

with-body

(with-body [resp : int body : cstr] :)

replace the body of a Response (mutates in place).

resp:int Response handle
bodynew body string

:int -- the same Response handle

(-> (ok "text/plain" "") (with-body "later"))

Since: H4

defn

with-status

(with-status [resp : int status : int] :)

replace the status code of a Response (mutates in place).

resp:int Response handle
statusnew HTTP status code

:int -- the same Response handle

(-> (ok "text/plain" "no") (with-status 503))

Since: H4

defn

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

defn

response

(response [status : int content-type : cstr body : cstr] :)

build an HTTP response with an arbitrary status code.

statusHTTP status code, e.g. 200, 201, 500
content-typevalue for the Content-Type header, e.g. "text/html"
bodyresponse 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

defn

resp-ok

(resp-ok [content-type : cstr body : cstr] :)

build a 200 OK response.

content-typevalue for the Content-Type header
bodyresponse body string

:int -- Response handle with status 200

(resp-ok "text/plain" "Hello, world!")

Since: H4

defn

not-found

(not-found [body : cstr] :)

build a 404 Not Found response with a text/plain body.

bodybody string (typically a short message)

:int -- Response handle with status 404

(not-found "no such resource")

Since: H4

defn

bad-request

(bad-request [body : cstr] :)

build a 400 Bad Request response with a text/plain body.

bodybody string (typically a short error message)

:int -- Response handle with status 400

(bad-request "missing id parameter")

Since: H4

Internal definitions
__resp-new