Procs
proc addGroup(app: Prologue; patterns: openArray[(Group, seq[UrlPattern])]) {....raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds multiple routes with handlers. Source Edit
proc addGroup(group: Group; route: string; handler: HandlerAsync; httpMethod = HttpGet; name = ""; middlewares: openArray[HandlerAsync] = @[]) {....raises: [RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
-
Adds a single route and handler. It checks whether route is duplicated.
Notes: The framework will automatically register HttpHead method, if httpMethod is HttpGet.
Source Edit proc addGroup(group: Group; route: string; handler: HandlerAsync; httpMethod: openArray[HttpMethod]; name = ""; middlewares: openArray[HandlerAsync] = @[]) {....raises: [RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds a single regex route and handler, but supports a set of HttpMethod. It also checks whether route is duplicated Source Edit
proc addRoute(app: Prologue; patterns: openArray[UrlPattern]; baseRoute = ""; middlewares: Option[seq[HandlerAsync]] = none(seq[HandlerAsync])) {....raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds multiple routes with handlers. Source Edit
proc addRoute(app: Prologue; route: Regex; handler: HandlerAsync; httpMethod = HttpGet; middlewares: openArray[HandlerAsync] = @[]) {. inline, ...raises: [], tags: [], forbids: [].}
-
Adds a single regex route with handler and don't check whether route is duplicated.
Notes: The framework will automatically register HttpHead method, if HttpMethod is HttpGet.
Source Edit proc addRoute(app: Prologue; route: Regex; handler: HandlerAsync; httpMethod: openArray[HttpMethod]; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [], tags: [], forbids: [].}
- Adds a single regex route and handler, but supports a set of HttpMethod. Source Edit
proc addRoute(app: Prologue; route: string; handler: HandlerAsync; httpMethod = HttpGet; name = ""; middlewares: openArray[HandlerAsync] = @[]) {....raises: [RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
-
Adds a single route and handler. It checks whether route is duplicated.
Notes: The framework will automatically register HttpHead method, if HttpMethod is HttpGet.
Source Edit proc addRoute(app: Prologue; route: string; handler: HandlerAsync; httpMethod: openArray[HttpMethod]; name = ""; middlewares: openArray[HandlerAsync] = @[]) {....raises: [RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds a single route and handler, but supports a set of HttpMethod. It also checks whether route is duplicated Source Edit
proc all(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with all HttpMethod. Source Edit
proc all(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with all HttpMethod. Source Edit
proc connect(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpConnect. Source Edit
proc connect(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpConnect. Source Edit
proc delete(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpDelete. Source Edit
proc delete(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpDelete. Source Edit
proc get(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpGet and HttpHead. Source Edit
proc get(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpGet and HttpHead. Source Edit
proc handleContext(app: Prologue; ctx: Context): owned(Future[void]) {....gcsafe, stackTrace: false, raises: [Exception], tags: [RootEffect], forbids: [].}
- Handles the context of each request. Todo Optimization Source Edit
proc handleRequest(app: Prologue; nativeRequest: NativeRequest; ctxTyp: typedesc[Context]): Future[void] {....gcsafe.}
- Handles the native request and sends response to the client. Source Edit
proc head(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpHead. Source Edit
proc head(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpHead. Source Edit
func newApp(settings: Settings = newSettings(); middlewares: openArray[HandlerAsync] = @[]; startup: openArray[Event] = @[]; shutdown: openArray[Event] = @[]; errorHandlerTable = newErrorHandlerTable( [(Http404, default404Handler), (Http500, default500Handler)]); appData = newStringTable(mode = modeCaseSensitive)): Prologue {. inline, ...raises: [ValueError, KeyError], tags: [], forbids: [].}
-
Creates a new App instance.
Params:
- `settings` is a global immutable setting which is visible to all handlers. - `middlewares` is a global sequence of middlewares. - `startup` is used to execute tasks before the application starts. - `shutdown` is used to execute tasks after the application stops. - `errorHandlerTable` stores HTTP codes and corresponding handlers. - `appData` is a global user-defined data.
Source Edit proc newAppQueryEnv(configFileExt: ConfigFileExt; loadJsonNode: proc (configPath: string): JsonNode; middlewares: openArray[HandlerAsync] = @[]; startup: openArray[Event] = @[]; shutdown: openArray[Event] = @[]; errorHandlerTable = newErrorHandlerTable( [(Http404, default404Handler), (Http500, default500Handler)]); appData = newStringTable(mode = modeCaseSensitive)): Prologue {. ...raises: [IOError, KeyError, EmptySecretKeyError, Exception], tags: [ReadEnvEffect, ReadDirEffect, RootEffect], forbids: [].}
- Creates a new App instance. The config file used to create the instance is loaded from a ./.config directory. The specific config file of that directory that is used is determined by querying the contents of the PROLOGUE environment variable, which must be set. Source Edit
proc newAppQueryEnv(middlewares: openArray[HandlerAsync] = @[]; startup: openArray[Event] = @[]; shutdown: openArray[Event] = @[]; errorHandlerTable = newErrorHandlerTable( [(Http404, default404Handler), (Http500, default500Handler)]); appData = newStringTable(mode = modeCaseSensitive)): Prologue {. inline, ...raises: [IOError, KeyError, EmptySecretKeyError, Exception], tags: [ReadEnvEffect, ReadDirEffect, RootEffect], forbids: [].}
- Creates a new App instance. by querying environment variables: PROLOGUE. Source Edit
proc options(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpOptions. Source Edit
proc options(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpOptions. Source Edit
proc patch(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPatch. Source Edit
proc patch(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPatch. Source Edit
proc post(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPost. Source Edit
proc post(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPost. Source Edit
proc put(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPut. Source Edit
proc put(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpPut. Source Edit
proc registerErrorHandler(app: Prologue; code: HttpCode; handler: ErrorHandler) {. inline, ...raises: [], tags: [], forbids: [].}
-
Registers a user-defined error handler. You can specify HttpCode and its corresponding handler.
When the HTTP code of response exists in the error handler table, corresponding handler will be executed.
Source Edit proc registerErrorHandler(app: Prologue; code: openArray[HttpCode]; handler: ErrorHandler) {.inline, ...raises: [], tags: [], forbids: [].}
-
Registers the same handler with a sequence of HttpCode. This is a helper function.
Example:
## Examples for all registerErrorHandler proc go404*(ctx: Context) {.async.} = resp "Something wrong!", Http404 proc go20x*(ctx: Context) {.async.} = resp "Ok!", Http200 proc go30x*(ctx: Context) {.async.} = resp "EveryThing else?", Http301 var app = newApp() app.registerErrorHandler(Http404, go404) app.registerErrorHandler({Http200 .. Http204}, go20x) app.registerErrorHandler(@[Http301, Http304, Http307], go30x) doAssert app.errorHandlerTable[Http404] == go404 doAssert app.errorHandlerTable[Http202] == go20x doAssert app.errorHandlerTable[Http304] == go30x
Source Edit proc registerErrorHandler(app: Prologue; code: set[HttpCode]; handler: ErrorHandler) {.inline, ...raises: [], tags: [], forbids: [].}
- Registers the same handler with a set of HttpCode. Source Edit
proc trace(app: Prologue; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpTrace. Source Edit
proc trace(group: Group; route: string; handler: HandlerAsync; name = ""; middlewares: openArray[HandlerAsync] = @[]) {.inline, ...raises: [ RouteError, KeyError, DuplicatedRouteError, DuplicatedReversedRouteError], tags: [], forbids: [].}
- Adds route and handler with HttpTrace. Source Edit
func use(app: var Prologue; middlewares: varargs[HandlerAsync]) {.inline, ...raises: [], tags: [], forbids: [].}
- Source Edit