No matching definitions.

httpd/response

src/httpd/response.tur

Response struct, constructors, and mutators.

Since: H4

defn

with-header

(with-header [resp : Response 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-header-set

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

set a header on a Response, replacing any existing

respResponse handle
keyheader name
valheader value

Response -- the same handle (for chaining)

(with-header-set (resp-ok "text/plain" "{}") "Content-Type" "application/json")

Since: tourist-on-stdlib-httpd H2

defn

resp-header

(resp-header [resp : Response name : cstr] :)

read a header of a Response by name (case-insensitive).

respResponse handle
nameheader name

(Option cstr) -- some(value), or none when the header is absent. The value belongs to the Response.

(resp-header (resp-ok "text/plain" "hi") "Content-Type")  ; => some("text/plain")

Since: tourist-on-stdlib-httpd H2

defn

with-body

(with-body [resp : Response 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-body-bytes

(with-body-bytes [resp : Response bytes ptr<void> len : int] :)

replace the body of a Response with raw bytes.

respResponse handle
bytessource buffer
lenbyte count

Response -- the same handle

(with-body-bytes (resp-ok "image/png" "") png-data png-len)

Since: tourist-on-stdlib-httpd H2

defn

with-status

(with-status [resp : Response 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 : Response] :)

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