addd GetHandler to exyus

2007-11-28 @ 03:51#

i took some time today to add a new simple GetHandler to the exyus engine this evening. i got the idea while i was scanning the source code and examples for web.py - another very nice HTTP programming library.

the idea is to allow folks to create a simple, static, resource with almost no code or other support files like XML/XSLT, etc. i did this by creating a class that only supports GET and allows you to initialize the content directly via a string or a single file.

below are some examples. note that the first class defines two explicit URLs for the same string resource. this is all legal. and the second class uses a simple pattern to link a URL folderpath (and any document name) to a single file resource.

// simple direct get handler
[UriPattern(@"/shopping/(?<tail>\.xcs)(.*)?",@"/shopping/hello(?<tail>\.xcs)(.*)?")]
public class StartPage : GetHandler
{
    public StartPage()
    {
        this.Content = "<h1>hello!</h1>";
        this.MaxAge = 600;
    }
}

// simple direct get handler
[UriPattern(@"/getpage/([^.]*)?(?<tail>\.xcs)(.*)?")]
public class getPage : GetHandler
{
    public getPage()
    {
        this.Content = Helper.ReadFile("/xcs/content/getpage.html");
        this.MaxAge = 600;
    }
}

// simple direct get handler
[UriPattern(@"/shopping/testing(?<tail>\.xcs)(.*)?")]
public class TestingPage : GetHandler
{
    public TestingPage()
    {
        this.Content = Helper.ReadFile("/xcs/content/testing.html");
        this.MaxAge = 600;
     }
}

code