urlconf for erlang

O2 and I are at it again – this time with a mixture of python, xslt and erlang soup’n up to provide what will be the best and best value e-marketting tool around. The python part is that our shop window is written in django, with lots of jQuery magic providing a slick UI. I’m particularly fond of jQuery and my favoured style of web development is to implement the back-end as a RESTful web service and then consume and decorate this web exposure with a dynamic UI. The reason behind django (as opposed to one of the millions of other web frameworks) is that we both know python inside out. And I get plenty of ruby hacking done both at work (where we are near OCD about capistrano) and in developing much of axiom.

So where does the erlang part come in? Well that’s not all up for public consumption, but suffice to say there is a fair chunk of what we’re planning to do which is what I would call “infrastructure programming” and that is something that erlang is basically perfect for. Not least of what we need is a distributed, fault tolerant grid without spending much money either building or hosting the thing, and again, we’re on to the right tool for the job.

Some of what we’ll be doing involves handling http requests, and for that, I’m currently in favour of using either mochiweb or yaws. For our needs, the former is a simpler choice but one thing that mochiweb doesn’t provide out of the box is a way to map requests to the appropriate chunk of request handling code. Our latest open source forray aims to add this capability, albeit in a way that isn’t specifically tied to mochiweb.

Enter urlconf-erlang. There’s no link because the source code still lives in a private repo and we’re not ready to release it yet. 🙂

Inspired by someone’s laudible effort to implement the django templating language in erlang, we decided to implement something akin to django’s url mapping system for our own evil purposes. Our current implementation only really deals with a single layer of mappings and does so by simply matching the url against a regex and returning the MFA (Module, Function, Args) configured against it. A quick peek at one of the test cases should make this a bit clearer:

named_arguments_supported_by_regex_impl(_) ->
    Path = "/users/fwnext-retail/billing-address",
    Rx = "/users/(?.*)/(?.*)$",
    Config = {
        [{Rx, my.controllers.users, {
            [uname, subcomponent]
            {mfa, {
                {uname, "fwnext-retail"},
                {subcomponent, "billing-address"}

As you can see there is some cruft because none of the Erlang regex libraries support named capture groups particularly well. In addition to this, we’re using the .re top level module (which is still not officially supported in R12B) as it is the only implementation we’ve found that is both fast and reliable. Because the choice of regex ibrary is likely to be a contentious point, we’ve taken the step of making the urlconf server a parameterized module, allowing you to pass in your own regex implementation instead of ours.

  1. #1 by Jdaazlert on April 8, 2009 - 3:42 am

    Thanks a lot, can I get some more details or tutorials about this?

    • #2 by loggerheadz on April 8, 2009 - 6:04 am

      Hi Jdaazlert,

      Thanks for your interest. I’ll post a tutorial and discuss the roadmap at some point in the next couple of days. The source code is going up onto github this morning (GMT) and you’re free to browse and/or clone the repo from here. The build is currently a bit fragile as the tests rely on another one of our *private* libraries which isn’t being open sourced right away. I’m also hoping to strip out that dependency over this weekend and finish off writing an install task into the makefile to make life a bit simpler.

      Here’s the link to github: http://github.com/hyperthunk/urlconf-erlang

  2. #3 by J on December 10, 2009 - 9:09 pm


    What was it like using Erlang to create your distributed, fault tolerant grid application? We are considering using Erlang, but it seems like we would have to re-invent the wheel every time we create a new application that we want to ‘gridify’ (i.e. having to deal with the ‘plumbing’ of making a program scalable, distributed, and fault tolerant for each new application we write). Is this unavoidable in Erlang or do you know of any pre-made gridifying elements we can build our application on top of to save time?

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: