Provides powerful routing ✨
Types
PathParamObj = object name*: string paramType*: string defaultValue*: string optional*: bool mutable*: bool
RequestModelObj = object name*: string typeName*: string target*: string ## JSON/XML/FormData/X-www-formurlencoded mutable*: bool
RouteDataObj = object pathParams*: seq[PathParamObj] requestModels*: seq[RequestModelObj] purePath*: string path*: string
RouteObject = JsonNode
Consts
onException = r"HappyXOnException"
Procs
proc convertJson(self: RequestModelData; body: string): JsonNode {. ...raises: [IOError, OSError, KeyError, ValueError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}
- Converts Request JSON to Python dict
proc exportRouteArgs(urlPath, routePath, body: NimNode): NimNode {. ...raises: [ValueError, RegexError], tags: [RootEffect], forbids: [].}
- Finds and exports route arguments
proc getRouteParams(routeData: RouteDataObj; found_regexp_matches: seq[RegexMatch2]; urlPath: string = ""; handlerParams: seq[HandlerParam] = @[]; body: string = ""; force: bool = false): RouteObject {. ...raises: [IOError, OSError, KeyError, ValueError], tags: [ReadIOEffect, WriteIOEffect], forbids: [].}
- Finds and exports route arguments
proc handleRoute(route: string): RouteDataObj {. ...raises: [ValueError, RegexError], tags: [RootEffect], forbids: [].}
-
Handles route and receive route data object.
Examples
dollar full: $argument?:word[m]=hello curvy full: {argument?:word[m]=hello} model full: [argument:ModelName:json]
proc newPathParamObj(name, paramType, defaultValue: string; optional, mutable: bool): PathParamObj {....raises: [], tags: [], forbids: [].}
proc newRequestModelObj(name, typeName, target: string; mutable: bool): RequestModelObj {. ...raises: [], tags: [], forbids: [].}
proc parseBoolOrJString(str: string): JsonNode {....raises: [], tags: [], forbids: [].}
proc parseFloatOrJString(str: string): JsonNode {....raises: [], tags: [], forbids: [].}
proc parseIntOrJString(str: string): JsonNode {....raises: [], tags: [], forbids: [].}
Macros
macro pathParams(body: untyped): untyped
-
pathParams provides path params assignment ✨.
Simple usage:
pathParams: # means that `arg` of type `int` is optional mutable param with default value `5` arg? int[m] = 5 # means that `arg1` of type `string` is optional mutable param with default value `"Hello"` arg1[m] = "Hello" # means that `arg2` of type `string` is immutable regex param arg2 re2"\d+u" # means that `arg3` of type `float` is mutable param arg3 float[m] # means that `arg4` of type `int` is optional mutable param with default value `10` arg4: type int mutable optional default = 10
macro registerRouteParamType(name, pattern: string; creator: untyped)