agrafix / Spock

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

Routes that match with any HTTP method #121

Closed redneb closed 7 years ago

redneb commented 7 years ago

Hi, is there a way to add a route that matches regardless of the HTTP method used? scotty has matchAny. It would also be nice to be able to find out what method was actually used.

agrafix commented 7 years ago

We currently don't have that in Spock as we have a separate "routing table" per method. You can still implement this combinator easily by iterating over all possible methods and wiring them up. Something like:

hookMethodAny path handler =
    forM_ [minBound..maxBound] $ \myMethod ->
    hookRoute myMethod path $ handler myMethod
redneb commented 7 years ago

Yeah, this is what I do currently. I was hopping for something more general, although I suspect that my application (which simply forwards requests to another server) will not encounter any nonstandard HTTP methods.

redneb commented 7 years ago

Another application that I had in mind, is the notFound route that scotty offers. Is there some other sensible way to implement this in Spock?

agrafix commented 7 years ago

Yes, you can use the error handler of SpockCfg, but you currently only get the Status. This can easily be extended if you are up for a PR :-)