Skip to content

Add regex based router#723

Open
danielcompton wants to merge 1 commit intometosin:masterfrom
danielcompton:dc/regex-router
Open

Add regex based router#723
danielcompton wants to merge 1 commit intometosin:masterfrom
danielcompton:dc/regex-router

Conversation

@danielcompton
Copy link

Reitit is very fast, but cannot support all routing structures that other routers like Bidi support, particular regex-based routes.

This PR is a proof of concept of one way that a regex based router could work with Reitit.

A more complete version of this PR would compile only the regex based routes to this router, and let the rest of the routes be handled by faster Reitit routers. You could also compile the regex based router to match on a path segment at a time, pruning routes before needing to evaluate a regular expression.

Before I go too much further, I wanted to get some feedback on the syntax for route definition and the overall approach. What do you think about this idea, and the way that path parameters are defined as regex's?

This unoptimized router is about 8-20x slower than regular Reitit in some informal testing.

Fixes #722

Reitit is very fast, but cannot support all routing structures that
other routers like Bidi support, particular regex-based routes.
@Deraen
Copy link
Member

Deraen commented Mar 28, 2025

This could be also interesting for frontend use, to optimize the artifact size (#540) because the Trie implementation generates quite a lot of JS code and the performance doesn't matter as much for FE routing.

I'll try to review this at some point.

@mthl
Copy link
Contributor

mthl commented Jan 1, 2026

Hello

[["articles/:year/:month/:slug"
  {:name :user/article,
   :parameters {:path {:year #"\d{4}"
                       :month #"\d{2}"
                       :slug #"[a-z0-9\-]+"}}}]]

Given that the regexp guard is defined in [:parameters :path] which is used by coercion and openapi, it seems that the regexp router is only compatible with schema and not with malli or clojure.spec which is not ideal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: 🐰 Important

Development

Successfully merging this pull request may close these issues.

Routing with regex based constraints

3 participants