Grammar-based dispatching – a step further

You may remember the idea of dispatching HTTP requests with Perl 6 grammars. Turned out to be funny and interesting, but wait, what’s the big deal? What’s good about a webapp that runs in the CLI, and dispatches only the strings given in the source code? Yeah, it’s funny, but is it practical? Not quite. So here we go with something practical this time.

Someone asked me about a HTTP requests parser. Looks like there alredy was one, built-in in HTTP::Server::Simple by mberends++. After adapting it to Rakudo’s needs (specs change) and to my needs (REQUEST_URI wasn’t working in it), and commiting some hacks of mine, i ended up with a PSGI server suitable for serving webapps. Webapps like our last week’s dispatcher. So here we go:

The code is pretty straightforward (methinks), so let’s just skip to the interesting part. Which is: it actually works. You can write a working PSGI app now, dispatching requests with a Perl 6 grammars. Cute, eh?