context

    Dark Mode
Search:
Group by:

Types

PathHandler = ref object
  handler*: HandlerAsync
  middlewares*: seq[HandlerAsync]
  Source Edit
Path = object
  route*: string
  httpMethod*: HttpMethod
  Source Edit
RePath = object
  route*: Regex
  httpMethod*: HttpMethod
  Source Edit
ReRouter = ref object
  callable*: seq[(RePath, PathHandler)]
  Source Edit
ReversedRouter = StringTableRef
  Source Edit
GlobalScope = ref object
  router*: Router
  reversedRouter*: ReversedRouter
  reRouter*: ReRouter
  appData*: StringTableRef
  settings*: Settings
  ctxSettings*: CtxSettings
Contains global data passed to Context.   Source Edit
Context = ref object of RootObj
  request*: Request
  response*: Response
  handled*: bool
  session*: Session
  ctxData*: StringTableRef
  gScope: GlobalScope
  middlewares: seq[HandlerAsync]
  size: int8
  first: bool
  Source Edit
AsyncEvent = proc (): Future[void] {...}{.closure, gcsafe.}
  Source Edit
SyncEvent = proc () {...}{.closure, gcsafe.}
  Source Edit
Event = object
  case async*: bool
  of true:
      asyncHandler*: AsyncEvent

  of false:
      syncHandler*: SyncEvent

  
startup or shutdown event which is executed once.   Source Edit
HandlerAsync = proc (ctx: Context): Future[void] {...}{.closure, gcsafe.}
  Source Edit
ErrorHandler = proc (ctx: Context): Future[void] {...}{.nimcall, gcsafe.}
  Source Edit
ErrorHandlerTable = TableRef[HttpCode, ErrorHandler]
  Source Edit
UploadFile = object
  filename*: string
  body*: string
Contains filename and body of a file uploaded by users.   Source Edit
PatternMatchingType = enum
  ptrnWildcard, ptrnParam, ptrnText
Kinds of elements that may appear in a mapping   Source Edit
BasePatternNode = object of RootObj
  isGreedy*: bool
  case kind*: PatternMatchingType
  of ptrnParam, ptrnText:
      value*: string

  of ptrnWildcard:
      nil

  
A token within a URL to be mapped. The URL is broken into 'knots' that make up a 'rope' (seq[BasePatternNode])   Source Edit
PatternNode = object of BasePatternNode
  case isLeaf*: bool
  of true:
      nil

  of false:
      children*: seq[PatternNode]

  case isTerminator*: bool
  of true:
      handler*: PathHandler

  of false:
      nil

  
A node within a routing tree, usually constructed from a BasePatternNode   Source Edit
Router = ref object
  data*: CritBitTree[PatternNode]
Container that holds HTTP mappings to handler functions   Source Edit

Procs

proc first=(ctx: Context; first: bool) {...}{.raises: [], tags: [].}
Internal function. Do not use.   Source Edit
proc middlewares=(ctx: Context; middlewares: seq[HandlerAsync]) {...}{.raises: [],
    tags: [].}
Internal function. Do not use.   Source Edit
proc addMiddlewares(ctx: Context; middleware: HandlerAsync) {...}{.inline,
    raises: [], tags: [].}
Internal function. Do not use.   Source Edit
proc addMiddlewares(ctx: Context; middleware: seq[HandlerAsync]) {...}{.inline,
    raises: [], tags: [].}
Internal function. Do not use.   Source Edit
proc execEvent(event: Event) {...}{.inline, raises: [Exception, ValueError, OSError],
                               tags: [RootEffect, TimeEffect].}
  Source Edit
proc save(uploadFile: UploadFile; dir: string; filename = "") {...}{.inline,
    raises: [OSError, IOError], tags: [ReadDirEffect, WriteIOEffect].}
Saves the UploadFile to dir.   Source Edit
proc newErrorHandlerTable(initialSize = defaultInitialSize): ErrorHandlerTable {...}{.
    raises: [], tags: [].}
Creates a new error handler table.   Source Edit
proc newErrorHandlerTable(pairs: openArray[(HttpCode, ErrorHandler)]): ErrorHandlerTable {...}{.
    raises: [Exception], tags: [RootEffect].}
Creates a new error handler table.   Source Edit
proc flash(ctx: Context; msgs: string; category = FlashLevel.Info) {...}{.inline,
    raises: [], tags: [].}
  Source Edit
proc flash(ctx: Context; msgs: string; category: string) {...}{.inline, raises: [],
    tags: [].}
  Source Edit
proc getFlashedMsgs(ctx: Context): seq[string] {...}{.inline, raises: [], tags: [].}
  Source Edit
proc getFlashedMsgsWithCategory(ctx: Context): seq[(string, string)] {...}{.inline,
    raises: [], tags: [].}
  Source Edit
proc getFlashedMsg(ctx: Context; category: FlashLevel): Option[string] {...}{.inline,
    raises: [KeyError], tags: [].}
  Source Edit
proc getFlashedMsg(ctx: Context; category: string): Option[string] {...}{.inline,
    raises: [KeyError], tags: [].}
  Source Edit
proc respond(ctx: Context; code: HttpCode; body: string;
             headers: ResponseHeaders): Future[void] {...}{.inline,
    raises: [ValueError, IOSelectorsException, KeyError, Exception],
    tags: [RootEffect].}
Sends response to the client generating from code, body and headers.   Source Edit
proc respond(ctx: Context): Future[void] {...}{.inline,
    raises: [ValueError, IOSelectorsException, KeyError, Exception],
    tags: [RootEffect].}
Sends response to the client generating from ctx.response.   Source Edit
proc respond(ctx: Context; code: HttpCode; body: string): Future[void] {...}{.inline,
    raises: [ValueError, IOSelectorsException, Exception], tags: [RootEffect].}
Sends response to the client generating from ctx.response.   Source Edit
proc send(ctx: Context; content: string): Future[void] {...}{.inline,
    raises: [ValueError, IOSelectorsException, Exception], tags: [RootEffect].}
Sends content to the client.   Source Edit
proc setCookie(ctx: Context; key, value: string; expires = "";
               maxAge: Option[int] = none(int); domain = ""; path = "";
               secure = false; httpOnly = false; sameSite = Lax) {...}{.inline,
    raises: [KeyError], tags: [].}
Sets Cookie for Response.   Source Edit
proc setCookie(ctx: Context; key, value: string; expires: DateTime | Time;
               maxAge: Option[int] = none(int); domain = ""; path = "";
               secure = false; httpOnly = false; sameSite = Lax) {...}{.inline.}
Sets Cookie for Response.   Source Edit
proc deleteCookie(ctx: Context; key: string; path = ""; domain = "") {...}{.inline,
    raises: [KeyError], tags: [TimeEffect].}
Deletes Cookie from Response.   Source Edit
proc defaultHandler(ctx: Context): Future[void] {...}{.raises: [Exception],
    tags: [RootEffect].}
Default handler with HttpCode 404.   Source Edit
proc default404Handler(ctx: Context): Future[void] {...}{.raises: [Exception],
    tags: [RootEffect].}
Default 404 pages.   Source Edit
proc default500Handler(ctx: Context): Future[void] {...}{.raises: [Exception],
    tags: [RootEffect].}
Default 500 pages.   Source Edit
proc setResponse(ctx: Context; code: HttpCode; body = ""; version = HttpVer11) {...}{.
    inline, raises: [], tags: [].}
Handy to make the response of ctx.   Source Edit
proc setResponse(ctx: Context; response: Response) {...}{.inline, raises: [],
    tags: [].}
Handy to make the response of ctx.   Source Edit
proc attachment(ctx: Context; downloadName: string; charset = "utf-8") {...}{.inline,
    raises: [ValueError], tags: [].}
attachment is used to specify the file which will be downloaded.
Params:
  • downloadName: The name of the file to be downloaded. If the
    length of the name is zero, the function will return immediately.
  • charset: The Encoding of the file. utf-8 is the default encoding.
  Source Edit
proc staticFileResponse(ctx: Context; filename, dir: string; mimetype = "";
                        downloadName = ""; charset = "utf-8"; bufSize = 40960;
                        headers = none(ResponseHeaders)): owned(Future[void]) {...}{.
    raises: [Exception], tags: [ReadDirEffect, RootEffect].}
Returns static files response. The following middlewares processing will be discarded.   Source Edit

Funcs

func gScope(ctx: Context): lent GlobalScope {...}{.raises: [], tags: [].}
  Source Edit
func size(ctx: Context): int8 {...}{.raises: [], tags: [].}
Internal function. Do not use.   Source Edit
func incSize(ctx: Context; num = 1) {...}{.raises: [], tags: [].}
Internal function. Do not use.   Source Edit
func first(ctx: Context): bool {...}{.raises: [], tags: [].}
Internal function. Do not use.   Source Edit
func middlewares(ctx: Context): lent seq[HandlerAsync] {...}{.raises: [], tags: [].}
  Source Edit
func initUploadFile(filename, body: string): UploadFile {...}{.raises: [], tags: [].}
Initiates a UploadFile.   Source Edit
func getUploadFile(ctx: Context; name: string): UploadFile {...}{.inline,
    raises: [KeyError], tags: [].}
Gets the UploadFile from request.   Source Edit
func newReversedRouter(): ReversedRouter {...}{.raises: [], tags: [].}
Creates a new reversed router table.   Source Edit
func initEvent(handler: AsyncEvent): Event {...}{.raises: [], tags: [].}
Initializes a new asynchronous event.   Source Edit
func initEvent(handler: SyncEvent): Event {...}{.raises: [], tags: [].}
Initializes a new synchronous event.   Source Edit
func newContext(request: Request; response: Response; gScope: GlobalScope): Context {...}{.
    raises: [], tags: [].}
Creates a new Context.   Source Edit
func newContext(ctx: Context; src: Context) {...}{.raises: [], tags: [].}
Creates a new Context by copying object and sharing ref object.   Source Edit
func newContextFrom(ctx: Context; src: Context) {...}{.raises: [], tags: [].}
Creates a new Context by moving object and sharing ref object.   Source Edit
func newContextTo(ctx: Context; src: Context) {...}{.raises: [], tags: [].}
Creates a new Context by moving object and copying necessary attributes.   Source Edit
func getSettings(ctx: Context; key: string): JsonNode {...}{.inline, raises: [],
    tags: [].}
Get settings from globalSetting. If key doesn't exist, nil will be returned.   Source Edit
func getCookie(ctx: Context; key: string; default = ""): string {...}{.inline,
    raises: [], tags: [].}
Gets the value of ctx.request.cookies[key] if key is in cookies. Otherwise, the default value will be returned.   Source Edit
func getPostParams(ctx: Context; key: string; default = ""): string {...}{.inline,
    raises: [], tags: [].}
Gets the parameters by HttpPost.   Source Edit
func getQueryParams(ctx: Context; key: string; default = ""): string {...}{.inline,
    raises: [], tags: [].}
Gets the query strings(for example, "www.google.com/hello?name=12", name=12).   Source Edit
func getPathParams(ctx: Context; key: string): string {...}{.inline, raises: [],
    tags: [].}
Gets the route parameters(for example, "/hello/{name}").   Source Edit
func getPathParams[T: BaseType](ctx: Context; key: string; default: T): T {...}{.
    inline.}
Gets the route parameters(for example, "/hello/{name}").   Source Edit
func getFormParams(ctx: Context; key: string; default = ""): string {...}{.inline,
    raises: [KeyError], tags: [].}
Gets the contents of the form if key exists. Otherwise default will be returned. If you need the filename of the form, use getUploadFile instead.   Source Edit
func urlFor(ctx: Context; handler: string;
            parameters: openArray[(string, string)] = @[];
            queryParams: openArray[(string, string)] = @[]; usePlus = true;
            omitEq = true): string {...}{.inline, raises: [KeyError, ValueError],
                                     tags: [].}
Returns the corresponding name of the handler.
Limitation:
Only supports two forms of Route:
  1. "/route/hello"
  2. "/route/{parameter}/other
  Source Edit
func abortExit(ctx: Context; code = Http401; body = "";
               headers = initResponseHeaders(); version = HttpVer11) {...}{.inline,
    raises: [AbortError], tags: [].}
Aborts the program. It raises AbortError.   Source Edit