Route autolinking for controllers. Parses {param:pattern} placeholders, builds regex with named groups, and derives controller proc names. Pattern table includes slug, uuid, semver, id etc. Used by the routes macro in router.nim.
Types
Autolinked = tuple[handleName, regexPath, path: string, params: Option[seq[(string, bool)]]]
RoutePattern = tuple[key: string, reKey: string, isOptional: bool]
RoutePatternsTable = OrderedTableRef[string, RoutePattern]
RouteSegment = tuple[isParam: bool, value: string]
- A static text (isParam == false) or {name:pattern} placeholder (isParam == true, value is the name) of a route path.
Procs
proc autolinkController(routePath: string; httpMethod: HttpMethod; isWebSocket = false): Autolinked {. ...raises: [ValueError, KeyError], tags: [], forbids: [].}
- Generates controller name and route regex from a routePath string. Parses {name:pattern} placeholders against RegexPatterns, builds a ^regex$ with named groups, and returns the autolinked tuple.
proc clientUrlExpr(base: NimNode; routePath: string): NimNode {.compileTime, ...raises: [], tags: [], forbids: [].}
- Turns base and "/storage/{bucket:slug}/cache/{key:slug}" into base & "/storage/" & bucket & "/cache/" & key. Param names become idents resolved at the use site.
proc routeSegments(routePath: string): seq[RouteSegment] {....raises: [], tags: [], forbids: [].}
- Splits a route path into static and param segments, in order. Used by service client codegen to build request URLs. Pattern validity itself is enforced by autolinkController.