HTTP router based on routing trees
Types
HttpVerb* = enum GET = "get", HEAD = "head", OPTIONS = "options", PUT = "put", POST = "post", DELETE = "delete"
- Available methods to associate a mapped handler with
Router*[H] = ref object verbTrees: CritBitTree[PatternNode[H]] logger: Logger
- Container that holds HTTP mappings to handler procs
RoutingArgs* = object pathArgs*: StringTableRef queryArgs*: StringTableRef
- Arguments extracted from a request while routing it
RoutingResultType* = enum routingSuccess, routingFailure
- Possible results of a routing operation
RoutingResult*[H] = object case status*: RoutingResultType of routingSuccess: handler*: H arguments*: RoutingArgs of routingFailure: nil
- Encapsulates the results of a routing operation
MappingError* = object of Exception
- Indicates an error while creating a new mapping
Procs
proc newRouter*[H](logger: Logger = newConsoleLogger()): Router[H]
- Creates a new Router instance
proc map*[H](router: Router[H]; handler: H; verb: string; pattern: string; headers: StringTableRef = newStringTable()) {.noSideEffect.}
- Add a new mapping to the given Router instance
proc compress*[H](router: Router[H])
- Compresses the entire contents of the given Router. Successive calls will recompress, but may not be efficient, so use this only when mapping is complete for the best effect
proc route*[H](router: Router[H]; requestMethod: string; requestUri: URI; requestHeaders: StringTableRef = newStringTable()): RoutingResult[H] {. noSideEffect.}
- Find a mapping that matches the given request description