agrafix / Spock

Another Haskell web framework for rapid development
https://www.spock.li
679 stars 56 forks source link

Wildcard route matching #52

Closed ondrap closed 8 years ago

ondrap commented 9 years ago

It should be possible to match against a request that starts with a prefix, for example:

wildcard GET "app" $ doStuff

should match all routes that start with /app/....

Questions:

Original:

I would need to catch a whole subtree to run an action. To catch the whole "/app/...", I tried this:

subcomponent "app" $ hookAny GET $ const servePage

However, that doesn't seem to work as expected - instead of 404, I get the servePage result when any non-handled page is requested - even outside of "/app". Is this an error or is it expected to behave this way? What is the proper way to do this?

agrafix commented 9 years ago

Currently hookAny is a catch-all handler, catching everything when nothing else matches. What you'd like to do is currently not possible. We would probably have to modify the routing algorithm implemented in reroute a bit. Would you be interested in giving this a shot?

ondrap commented 9 years ago

Ok, I'll try to see this as soon as I finish some projects I'm doing right now... I'll see if I am able to grasp the type labyrinth that makes the whole thing work...

agrafix commented 9 years ago

Okay, thanks :-) In 2 weeks I will have more time myself and could take a look. If you're stuck or have questions let me know.

crabmusket commented 8 years ago

This is essentially nested routing, right? I've been looking around at nested routing solutions in Haskell recently, and there don't seem to be a ton of them!

agrafix commented 8 years ago

Depends on what you mean by nested routing. Nested routing w/o capturing parameters is possible with Spock (subcomponent).

crabmusket commented 8 years ago

Spock's existing routing seems great - I love the use of HVect to build handlers with typesafe arguments for route parameters. Essentially I'm looking for a nested version of that. I'm going to have a swing at writing something myself and see how it goes.

The next frontier is making it reversible, but that seems wayyy too hard for now :p

agrafix commented 8 years ago

We've already started working on that some time ago, but did not have the time to finish it yet. See the branch in reroute: https://github.com/agrafix/reroute/tree/subcomponents . If you like you can take that as a base and continue working on it - I'll be happy to guide you!

agrafix commented 8 years ago

I've updated the issue to make it more clear

crabmusket commented 8 years ago

Since I'm here now (thanks, GitHub notifications!) I shall mention I'm still toying with ideas around this. I've started a library based on the same central idea as reroute (heterogeneous lists) but with other goals. Hopefully I'll have something demonstrable soon.

(I've been doing a lot of work in Laravel recently and the experience is leading me towards designing my own Haskell micro-framework. It's a bit of a non sequitur to say PHP has influenced my ideas for a Haskell framework, but we'll see...)

agrafix commented 8 years ago

We might be working on this at ZuriHac but if you already have a design then maybe you could share so we could iterate on that? :-)

crabmusket commented 8 years ago

Ooh, that''s great to hear. If only I lived somewhere that had events like that :relieved:. I'll send you an email!