Types
Response = object httpVersion*: HttpVersion code*: HttpCode headers*: ResponseHeaders body*: string
- Source Edit
Funcs
func `$`(response: Response): string {...}{.raises: [ValueError], tags: [].}
- Gets the string form of Response. Source Edit
func initResponse(httpVersion: HttpVersion; code: HttpCode; headers = [ ("Content-Type", "text/html; charset=UTF-8")].initResponseHeaders; body = ""): Response {...}{. inline, raises: [], tags: [].}
- Initializes a response. Source Edit
func initResponse(httpVersion: HttpVersion; code: HttpCode; headers: openArray[(string, string)]; body = ""): Response {...}{. inline, raises: [KeyError], tags: [].}
- Initializes a response. Source Edit
func abort(code = Http401; body = ""; headers = initResponseHeaders(); version = HttpVer11): Response {...}{.inline, raises: [], tags: [].}
- Returns the response with Http401 code(do not raise exception). Source Edit
func redirect(url: string; code = Http301; body = ""; delay = 0; headers = initResponseHeaders(); version = HttpVer11): Response {...}{. inline, raises: [KeyError, ValueError], tags: [].}
- Redirects to new url. Source Edit
func error404(code = Http404; body = "<h1>404 Not Found!</h1>"; headers = initResponseHeaders(); version = HttpVer11): Response {...}{. inline, raises: [], tags: [].}
- Creates an error 404 response. Source Edit
func htmlResponse(text: string; code = Http200; headers = initResponseHeaders(); version = HttpVer11): Response {...}{.inline, raises: [], tags: [].}
- Content-Type: text/html; charset=UTF-8. Source Edit
func plainTextResponse(text: string; code = Http200; headers = initResponseHeaders(); version = HttpVer11): Response {...}{. inline, raises: [], tags: [].}
- Content-Type: text/plain. Source Edit
func jsonResponse(text: JsonNode; code = Http200; headers = initResponseHeaders(); version = HttpVer11): Response {...}{. inline, raises: [], tags: [].}
- Content-Type: application/json. Source Edit
Macros
macro respDefault(code: HttpCode)
- Uses default error handler registered in the error handler table if existing. Source Edit
macro resp(body: string; code = Http200; version = HttpVer11)
- Handy to make a response of ctx. Source Edit
macro resp(response: Response)
- Handy to make a response of ctx. Source Edit
Templates
template hasHeader(response: Response; key: string): bool
- Returns true if key is in the response. Source Edit
template getHeader(response: Response; key: string): seq[string]
- Retrieves value of response.headers[key]. Source Edit
template getHeaderOrDefault(response: Response; key: string; default = @[""]): seq[ string]
- Retrieves value of response.headers[key]. Otherwise default will be returned. Source Edit
template setHeader(response: var Response; key, value: string)
- Sets the header values of the response. Source Edit
template setHeader(response: var Response; key: string; value: seq[string])
- Sets the header values of the response. Source Edit
template addHeader(response: var Response; key, value: string)
- Adds header values to the existing HttpHeaders. Source Edit
template setCookie(response: var Response; key, value: string; expires = ""; maxAge: Option[int] = none(int); domain = ""; path = ""; secure = false; httpOnly = false; sameSite = Lax)
- Sets the cookie of response. Source Edit
template setCookie(response: var Response; key, value: string; expires: DateTime | Time; maxAge: Option[int] = none(int); domain = ""; path = ""; secure = false; httpOnly = false; sameSite = Lax)
- Sets the cookie of response. Source Edit
template deleteCookie(response: var Response; key: string; value = ""; path = ""; domain = "")
- Deletes the cookie of the response. Source Edit