package naboris

  1. Overview
  2. Docs

Module for creating and sending responses.

type t
val default : unit -> t

Creates a default response record with empty headers and a 200 status.

val status : int -> t -> t

Creates new response from input response with status of int.

val json : 'sessionData Req.t -> string -> t -> unit Lwt.t

Sends response t with body string. Adding headers Content-type: application/json and Connection: close

This function will end the http request/response lifecycle.

val html : 'sessionData Req.t -> string -> t -> unit Lwt.t

Sends response t with body string. Adding headers Content-type: text/html and Connection: close

This function will end the http request/response lifecycle.

val text : 'sessionData Req.t -> string -> t -> unit Lwt.t

Sends response t with body string. Adding headers Content-type: text/plain and Connection: close

This function will end the http request/response lifecycle.

val raw : 'sessionData Req.t -> string -> t -> unit Lwt.t

Sends response t with body string.

This function will not add any headers other than Connection: close. This function will end the http request/response lifecycle.

val addHeader : (string * string) -> t -> t

Creates new response from t with header (string, string) added.

val static : string -> string list -> 'sessionData Req.t -> t -> unit Lwt.t

Opens file starting at path string and following list(string). Sets Content-type header based on file extension. If type cannot be inferred text/plain is used. Responds with 404 if file does not exist.

This function will end the http request/response lifecycle.

val redirect : string -> 'sessionData Req.t -> t -> unit Lwt.t

Sets Location header to string and responds with 302. Redirecting client to string.

val reportError : 'sessionData Req.t -> exn -> unit

Report an error exn to Httpaf.

val setSessionCookies : string -> t -> t

Adds Set-Cookie header to response t with sessionId string as a value. Uses "nab.sid" as the key for parsing the cookie later. Uses 30 days Max-Age for expiration.

These will be configurable in future versions.