java.lang.Object
dev.mccue.jdk.httpserver.regexrouter.RegexRouter
All Implemented Interfaces:
HttpHandler

public final class RegexRouter extends Object implements HttpHandler
Implementation of a Router that just does a linear scan through regexes.

This was chosen for my demo since it is the easiest thing to implement, not because it is the most performant.

That being said, this seems to be roughly how Django handles routing.

From the django docs

  • Django runs through each URL pattern, in order, and stops at the first one that matches the requested URL, matching against path_info.
  • Once one of the URL patterns matches, Django imports and calls the given view, which is a Python function (or a class-based view). The view gets passed the following arguments:
    • An instance of HttpRequest.
    • If the matched URL pattern contained no named groups, then the matches from the regular expression are provided as positional arguments.
    • The keyword arguments are made up of any named parts matched by the path expression that are provided, overridden by any arguments specified in the optional kwargs argument to django.urls.path() or django.urls.re_path().

For the syntax of declaring a named group, this stack overflow question should be useful.