Hey Juerd! I recently posted a module that encapsulates this exact concept - we really had the exact same idea here, see
for my code (which is still young and wants for features) It let's you forget about all the "server stuff" and just map your functions to the requesting urls, you can define a match by regex, string or a more complicated function that decides... see the forthcoming documentation, or the code itself for now.