src/mummy/routers

Source   Edit  

Types

RequestErrorHandler = proc (request: Request; e: ref Exception) {....gcsafe.}
Source   Edit  
Router = object
  notFoundHandler*: RequestHandler ## Called when no routes match the request URI
  methodNotAllowedHandler*: RequestHandler ## Called when the HTTP method is not registered for the route
  errorHandler*: RequestErrorHandler ## Called when the route request handler raises an Exception
  routes*: seq[Route]
Routes HTTP requests. See addRoute for more info. Source   Edit  

Procs

proc addRoute(router: var Router; httpMethod, route: string | static string;
              handler: RequestHandler)
Adds a route to the router. Routes are a path string and an HTTP method. When a request comes in, it is tested against the routes in the order they were added. The handler for the first matching route is called. The route path can have * and ** wildcards. The * wildcard represents 0 or more characters, excluding /. Valid uses are: "/" (wildcard path segment) "/.json" (wildcard prefix) "/page_" (wildcard suffix) "/_something_" (wildcard prefix and suffix) The `*` wildcard represents 1 or more path segments delimited by /. Valid uses are: "/" (wildcard path) "//thing" (wildcard path with suffix) "/thing/** (wildcard path with prefix) See tests/test_routers.nim for more complex routing examples. Source   Edit  
proc delete(router: var Router; route: string | static string;
            handler: RequestHandler)
Adds a route for DELETE requests. See addRoute for more info. Source   Edit  
proc get(router: var Router; route: string | static string;
         handler: RequestHandler)
Adds a route for GET requests. See addRoute for more info. Source   Edit  
proc head(router: var Router; route: string | static string;
          handler: RequestHandler)
Adds a route for HEAD requests. See addRoute for more info. Source   Edit  
proc options(router: var Router; route: string | static string;
             handler: RequestHandler)
Adds a route for OPTIONS requests. See addRoute for more info. Source   Edit  
proc patch(router: var Router; route: string | static string;
           handler: RequestHandler)
Adds a route for PATCH requests. See addRoute for more info. Source   Edit  
proc post(router: var Router; route: string | static string;
          handler: RequestHandler)
Adds a route for POST requests. See addRoute for more info. Source   Edit  
proc put(router: var Router; route: string | static string;
         handler: RequestHandler)
Adds a route for PUT requests. See addRoute for more info. Source   Edit  
proc toHandler(router: Router): RequestHandler {....raises: [], tags: [],
    forbids: [].}
Source   Edit  

Converters

converter convertToHandler(router: Router): RequestHandler {....raises: [],
    tags: [], forbids: [].}
Source   Edit