src/prologue/core/response

Types

Response = object
  httpVersion*: HttpVersion
  code*: HttpCode
  headers*: HttpHeaders
  body*: string
  Source Edit

Procs

proc `$`(response: Response): string {...}{.raises: [ValueError], tags: [].}
Stringify response.   Source Edit
proc initResponse(httpVersion: HttpVersion; code: HttpCode; headers = [
    ("Content-Type", "text/html; charset=UTF-8")].newHttpHeaders; body = ""): Response {...}{.
    raises: [], tags: [].}
Initializes response.   Source Edit
proc hasHeader(response: Response; key: string): bool {...}{.inline, raises: [], tags: [].}
Returns true if key is in the response.   Source Edit
proc setHeader(response: var Response; key, value: string) {...}{.inline, raises: [], tags: [].}
Sets the header values of the response.   Source Edit
proc setHeader(response: var Response; key: string; value: sink seq[string]) {...}{.inline,
    raises: [], tags: [].}
Sets the header values of the response.   Source Edit
proc addHeader(response: var Response; key, value: string) {...}{.inline, raises: [KeyError],
    tags: [].}
Adds header values to the existing HttpHeaders.   Source Edit
proc setCookie(response: var Response; key, value: string; expires = "";
              maxAge: Option[int] = none(int); domain = ""; path = ""; secure = false;
              httpOnly = false; sameSite = Lax) {...}{.inline, raises: [KeyError], tags: [].}
Sets the cookie of response.   Source Edit
proc setCookie(response: var Response; key, value: string; expires: DateTime | Time;
              maxAge: Option[int] = none(int); domain = ""; path = ""; secure = false;
              httpOnly = false; sameSite = Lax) {...}{.inline.}
Sets the cookie of response.   Source Edit
proc deleteCookie(response: var Response; key: string; value = ""; path = ""; domain = "") {...}{.
    inline, raises: [KeyError], tags: [TimeEffect].}
  Source Edit

Funcs

func abort(code = Http401; body = ""; headers = newHttpHeaders(); version = HttpVer11): Response {...}{.
    inline, raises: [], tags: [].}
  Source Edit
func redirect(url: string; code = Http301; body = ""; delay = 0; headers = newHttpHeaders();
             version = HttpVer11): Response {...}{.inline, raises: [KeyError, ValueError],
    tags: [].}
redirect to new url.   Source Edit
func error404(code = Http404; body = "<h1>404 Not Found!</h1>";
             headers = newHttpHeaders(); version = HttpVer11): Response {...}{.inline,
    raises: [], tags: [].}
404 HTML.   Source Edit
func htmlResponse(text: string; code = Http200; headers = newHttpHeaders();
                 version = HttpVer11): Response {...}{.inline, raises: [], tags: [].}
Content-Type: text/html; charset=UTF-8.   Source Edit
func plainTextResponse(text: string; code = Http200; headers = newHttpHeaders();
                      version = HttpVer11): Response {...}{.inline, raises: [], tags: [].}
Content-Type: text/plain.   Source Edit
func jsonResponse(text: JsonNode; code = Http200; headers = newHttpHeaders();
                 version = HttpVer11): Response {...}{.inline, raises: [], tags: [].}
Content-Type: application/json.   Source Edit

Macros

macro resp(body: string; code = Http200)
Handy to make a response of ctx.   Source Edit
macro resp(response: Response)
Handy to make a response of ctx.   Source Edit