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(HttpMethod 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(HttpMethod[] methods, string pattern, HttpRequestHandler handler)
addMapping
PathHandler addMapping(HttpMethod method, string[] patterns, HttpRequestHandler handler)
addMapping
PathHandler addMapping(HttpMethod[] methods, string[] patterns, HttpRequestHandler handler)
addMapping
PathHandler addMapping(string pattern, HttpRequestHandler handler)
handle
void handle(ServerHttpRequest request, ServerHttpResponse response)

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.

registerHandlers
void registerHandlers()

Adds mappings to this path handler which correspond to functions defined in the given symbol which have been annotated with the @PathMapping attribute (or any simplified aliases like @GetMapping).

setNotFoundHandler
PathHandler setNotFoundHandler(HttpRequestHandler handler)

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