Types
AsyncEvent = proc (): Future[void] {.closure, ...gcsafe.}
- 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
Context = ref object of RootObj request*: Request response*: Response handled*: bool session*: Session ctxData*: StringTableRef
- Source Edit
ErrorHandler = proc (ctx: Context): Future[void] {.nimcall, ...gcsafe.}
- Source Edit
ErrorHandlerTable = TableRef[HttpCode, ErrorHandler]
- 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
GlobalScope = ref object router*: Router reversedRouter*: ReversedRouter reRouter*: ReRouter appData*: StringTableRef settings*: Settings ctxSettings*: CtxSettings
- Contains global data passed to Context. Source Edit
HandlerAsync = proc (ctx: Context): Future[void] {.closure, ...gcsafe.}
- Source Edit
PathHandler = ref object handler*: HandlerAsync middlewares*: seq[HandlerAsync]
- Source Edit
PatternMatchingType = enum ptrnWildcard, ptrnParam, ptrnText
- Kinds of elements that may appear in a mapping 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
ReRouter = ref object callable*: seq[(RePath, PathHandler)]
- Source Edit
ReversedRouter = StringTableRef
- Source Edit
Router = ref object data*: CritBitTree[PatternNode]
- Container that holds HTTP mappings to handler functions Source Edit
UploadFile = object filename*: string body*: string
- Contains filename and body of a file uploaded by users. Source Edit
Procs
proc addMiddlewares(ctx: Context; middleware: HandlerAsync) {.inline, ...raises: [], tags: [], forbids: [].}
- Internal function. Do not use. Source Edit
proc addMiddlewares(ctx: Context; middleware: seq[HandlerAsync]) {.inline, ...raises: [], tags: [], forbids: [].}
- Internal function. Do not use. Source Edit
proc attachment(ctx: Context; downloadName: string; charset = "utf-8") {.inline, ...raises: [], tags: [], forbids: [].}
-
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 default404Handler(ctx: Context): Future[void] {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc default500Handler(ctx: Context): Future[void] {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Source Edit
proc defaultHandler(ctx: Context): Future[void] {....raises: [Exception], tags: [RootEffect], forbids: [].}
- Default handler with HttpCode 404. Source Edit
proc deleteCookie(ctx: Context; key: string; path = ""; domain = "") {.inline, ...raises: [KeyError], tags: [TimeEffect], forbids: [].}
- Deletes Cookie from Response. Source Edit
proc flash(ctx: Context; msgs: string; category = FlashLevel.Info) {.inline, ...raises: [], tags: [], forbids: [].}
- Sets flash messages. Source Edit
proc getFlashedMsg(ctx: Context; category: FlashLevel): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Source Edit
proc getFlashedMsg(ctx: Context; category: string): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Source Edit
proc getFlashedMsgs(ctx: Context): seq[string] {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
proc getFlashedMsgsWithCategory(ctx: Context): seq[(string, string)] {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit
func getFormParams(ctx: Context; key: string; default = ""): string {.inline, ...raises: [KeyError], tags: [], forbids: [].}
-
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. Returns the default value (which is an empty string if unspecified) if the form param does not exist.
getFormParams handles both form-urlencoded and multipart/form-data.
Source Edit func getFormParamsOption(ctx: Context; key: string): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
-
Gets the contents of the form if key exists. If you need the filename of the form, use getUploadFile instead. Returns none(string) if the form param does not exist
getFormParams handles both form-urlencoded and multipart/form-data.
Source Edit func getPathParams(ctx: Context; key: string): string {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Gets the route parameters(for example, "/hello/{name}"). Returns an empty string if the param does not exist. Source Edit
func getPathParams[T: BaseType](ctx: Context; key: string; default: T): T {. inline.}
- Gets the route parameters(for example, "/hello/{name}"). Returns the default value if the param does not exist. Source Edit
func getPathParamsOption(ctx: Context; key: string): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Gets a route parameter(for example, "/hello/{name}"). Returns none(string) if the param does not exist. Source Edit
func getPostParams(ctx: Context; key: string; default = ""): string {.inline, ...raises: [KeyError], tags: [], forbids: [].}
-
Gets a param from the HttpPost parameters. Returns the default value (which is an empty string if unspecified) if the param is not in the post parameters.
getPostParams only handles form-urlencoded types.
Source Edit func getPostParamsOption(ctx: Context; key: string): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
-
Gets a param from the HttpPost parameters. Returns none(string) if the request method is not HttpPost or the param is not in the post-parameters.
getPostParams only handles form-urlencoded types.
Source Edit func getQueryParams(ctx: Context; key: string; default = ""): string {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Gets a param from the query strings(for example, "www.google.com/hello?name=12", name=12). Returns the default value if the param does not exist. Source Edit
func getQueryParamsOption(ctx: Context; key: string): Option[string] {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Gets a param from the query strings. Returns none(string) if the param does not exist. (for example, "www.google.com/hello?name=12", name=12). Source Edit
func getSettings(ctx: Context; key: string): JsonNode {.inline, ...raises: [], tags: [], forbids: [].}
- Get settings from globalSetting. If key doesn't exist, nil will be returned. Source Edit
func getUploadFile(ctx: Context; name: string): UploadFile {.inline, ...raises: [KeyError], tags: [], forbids: [].}
- Gets the UploadFile from request. Source Edit
func gScope(ctx: Context): lent GlobalScope {....raises: [], tags: [], forbids: [].}
- Source Edit
func initEvent(handler: AsyncEvent): Event {....raises: [], tags: [], forbids: [].}
- Initializes a new asynchronous event. Source Edit
func initUploadFile(filename, body: string): UploadFile {....raises: [], tags: [], forbids: [].}
- Initiates a UploadFile. Source Edit
func middlewares(ctx: Context): lent seq[HandlerAsync] {....raises: [], tags: [], forbids: [].}
- Source Edit
proc middlewares=(ctx: Context; middlewares: seq[HandlerAsync]) {....raises: [], tags: [], forbids: [].}
- Internal function. Do not use. Source Edit
func newContextFrom(ctx: Context; src: Context) {....deprecated, raises: [], tags: [], forbids: [].}
- Source Edit Creates a new Context by moving object and sharing ref object.
func newContextTo(ctx: Context; src: Context) {....deprecated, raises: [], tags: [], forbids: [].}
- Source Edit Creates a new Context by moving object and copying necessary attributes.
proc newErrorHandlerTable(initialSize = defaultInitialSize): ErrorHandlerTable {. ...raises: [], tags: [], forbids: [].}
- Creates a new error handler table. Source Edit
proc newErrorHandlerTable(pairs: openArray[(HttpCode, ErrorHandler)]): ErrorHandlerTable {. ...raises: [], tags: [], forbids: [].}
- Creates a new error handler table. Source Edit
func newReversedRouter(): ReversedRouter {....raises: [], tags: [], forbids: [].}
- Creates a new reversed router table. Source Edit
proc respond(ctx: Context): Future[void] {.inline, ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Sends response to the client generating from ctx.response. Source Edit
proc respond(ctx: Context; code: HttpCode; body: string): Future[void] {.inline, ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Sends response to the client generating from ctx.response. Source Edit
proc respond(ctx: Context; code: HttpCode; body: string; headers: ResponseHeaders): Future[void] {.inline, ...raises: [Exception], tags: [RootEffect], forbids: [].}
- Sends response to the client generating from code, body and headers. Source Edit
proc save(uploadFile: UploadFile; dir: string; filename = "") {.inline, ...raises: [OSError, IOError], tags: [ReadDirEffect, WriteIOEffect], forbids: [].}
- Saves the UploadFile to dir. Source Edit
proc setCookie(ctx: Context; cookie: Cookie) {....raises: [KeyError], tags: [], forbids: [].}
- Sets Cookie for Response. Source Edit
proc setResponse(ctx: Context; code: HttpCode; body = ""; version = HttpVer11) {. inline, ...raises: [], tags: [], forbids: [].}
- Handy to make the response of ctx. Source Edit
proc setResponse(ctx: Context; response: Response) {.inline, ...raises: [], tags: [], forbids: [].}
- Handy to make the response of ctx. Source Edit
proc staticFileResponse(ctx: Context; filename, dir: string; mimetype = ""; downloadName = ""; charset = "utf-8"; bufSize = 40960; headers = none(ResponseHeaders)): owned(Future[void]) {. ...stackTrace: false, raises: [Exception], tags: [ReadDirEffect, RootEffect], forbids: [].}
- Returns static files response. The following middlewares processing will be discarded. 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: [], forbids: [].}
-
Returns the corresponding name of the handler.
Limitation: Only supports two forms of Route:
1. "/route/hello" 2. "/route/{parameter}/other
Source Edit