Nested Route 404 Behavior change proposal

0 views
Skip to first unread message

Matt Parsons

unread,
1:19 PM (6 hours ago) 1:19 PM
to Yesod Web Framework
When you define a nested route, it is greedy - if the route prefix matches, but then the route fails to match, it will send a 404. This means that each prefix must be unique, or later ones will never trigger. Example:

```
/  IndexR POST GET

/foo: FooR
    / FooIndexR POST GET
    /#{FooId} ShowFooR POST GET

/foo: OtherFooR
    /test TestFooR
    /neat NeatFooR
```

If you request to `/foo/neat` then this will always fail, because the first `/foo` capture works and commits to that subset of the routing structure.

I want to change the default behavior of this so that we fall through on nested routes. With this change, requesting to `/foo/neat` would succeed - after `FooR` dispatch doesn't get a match, we will then continue trying the next things in the route.

Why do this? It supports incrementally introducing nested routes that can be divided by team. Consider an original structure:

```
/ IndexR 
/foo/ FooIndexR
/foo/#FooId FooShowR
/foo/neat FooNeatR
/foo/test FooTestR
```

Suppose that we have two teams responsible for these routes. We want to split the routes based on team ownership. With fallthrough, we can do that - `FooR` is owned by one team, and `OtherFooR` is owned by the other team. Indeed, we can do this incrementally:

```
/ IndexR 

/foo: FooR
    / FooIndexR
    /#FooId FooShowR

/foo/neat FooNeatR
/foo/test FooTestR
```

With fallthrough, this works. We can segment a single route out. Without fallthrough, this *also* fails.

The cost is that a true 404 will now have to go through the entire routing table, where now it will terminate with 404 more quickly.

While I can make this potentially customizable, right now it relies on linear pattern matching on the route structure to know whether or not fallthrough is reasonable or not. If I get around to making a trie-based router for yesod, then this will not easily support the no-fallthrough behavior.

Posting here to get some insights from yesod users about what they'd like to see here
Reply all
Reply to author
Forward
0 new messages