PathHandler

A request handler that maps incoming requests to a particular handler based on the request's URL path and/or HTTP method (GET, POST, etc.).

Use the various overloaded versions of the addMapping(...) method to add handlers to this path handler. When handling requests, this path handler will look for matches deterministically in the order you add them. Therefore, adding mappings with conflicting or duplicate paths will cause the first one to always be called.

Path patterns should be defined according to the rules from the path-matcher library, found here: https://github.com/andrewlalis/path-matcher

Constructors

this
this()

Constructs a new path handler with initially no mappings, and a default notFoundHandler that simply sets a 404 status.

Members

Functions

addMapping
PathHandler addMapping(Method method, string pattern, HttpRequestHandler handler)

Adds a mapping to this handler, such that requests which match the given method and pattern will be handed off to the given handler.

addMapping
PathHandler addMapping(Method[] methods, string pattern, HttpRequestHandler handler)
addMapping
PathHandler addMapping(Method method, string[] patterns, HttpRequestHandler handler)
addMapping
PathHandler addMapping(Method[] methods, string[] patterns, HttpRequestHandler handler)
addMapping
PathHandler addMapping(string pattern, HttpRequestHandler handler)
addMapping
PathHandler addMapping(Method method, string pattern, HttpRequestHandlerFunction func)
addMapping
PathHandler addMapping(string pattern, HttpRequestHandlerFunction func)
handle
void handle(HttpRequestContext ctx)

Handles a request by looking for a mapped handler whose method and pattern match the request's, and letting that handler handle the request. If no match is found, the notFoundHandler will take care of it.

setNotFoundHandler
PathHandler setNotFoundHandler(HttpRequestHandler handler)

Sets the handler that will be called for requests that don't match any pre-configured mappings.

Inherited Members

From HttpRequestHandler

handle
void handle(HttpRequestContext ctx)

Handles an HTTP request. Note that this method may be called from multiple threads, as requests may be processed in parallel, so you should avoid performing actions which are not thread-safe.