supranim/controller

Types

BodyData = TableRef[string, string]

Lets

keypair = crypto_box_keypair()

Procs

proc getBodyData[T: BodyData | JsonNode](req: var Request; dataType: typedesc[T]): Option[
    T]
Returns the body data from Request as JsonNode
proc getBodyDataJson(req: var Request): SomeBodyData {....raises: [], tags: [],
    forbids: [].}

Returns the body fields from Request. When called for the first time it will decode the body and store the result in BodyData table.

Note this must be called only when the provided body is JSON. Invalid JSON will be rejected and the returned value will be none.

proc getClientId(req: var Request): Option[string] {....raises: [KeyError],
    tags: [TimeEffect], forbids: [].}
Returns the client-side ssid from Request
proc getFields(req: var Request): seq[(string, string)] {....raises: [], tags: [],
    forbids: [].}
Decodes Request body
proc getFieldsJson(req: Request): JsonNode {....raises: [], tags: [], forbids: [].}
proc getFieldsTable(req: var Request): SomeBodyData {.inline, ...raises: [],
    tags: [], forbids: [].}
An alias of getSomeBodyData
proc getFieldsTableJson(req: var Request): SomeBodyData {.inline, ...raises: [],
    tags: [], forbids: [].}
An alias of getBodyDataJson
proc getQueryTable(req: var Request): TableRef[string, string] {.inline,
    ...raises: [], tags: [], forbids: [].}
Retrieve query parameters as a table
proc getRequestBody(req: var Request): string {....raises: [], tags: [],
    forbids: [].}
Retrieves Request body
proc getSessionCookie(req: var Request): ref Cookie {....raises: [KeyError],
    tags: [TimeEffect], forbids: [].}
Returns the client-side ssid Cookie from Request
proc getSomeBodyData(req: var Request): SomeBodyData {....raises: [], tags: [],
    forbids: [].}

Returns the body fields from Request. When called for the first time it will decode the body and store the result in BodyData table.

If BodyData is already set, it will return the existing table.

proc params(req: Request): TableRef[string, string] {....raises: [], tags: [],
    forbids: [].}
Returns the route parameters from Request
proc setParams(req: var Request; params: TableRef[string, string]) {....raises: [],
    tags: [], forbids: [].}
Sets the route parameters in Request

Macros

macro go(id: untyped)
Redirects to a specific GET route using the controller identifier.
macro go(id: untyped; params: typed)
Redirects to a specific GET route using the controller identifier. This macro adds support for redirecting with query parameters.
macro newController(name, body: untyped)

Templates

template ctrl(name, body: untyped)
template isAuth(): bool
template redirectTo(controllerIdentName: typed)
An alias of go macro that redirects to specific GET route using the controller name.
template storage(path: string): string