Created
January 31, 2011 14:24
-
-
Save kevinswiber/804083 to your computer and use it in GitHub Desktop.
An example of a Tabasco resource.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using System.Collections.Generic; | |
using NRack.Helpers; | |
namespace Tabasco.Example | |
{ | |
[Resource("/")] | |
public class Main | |
{ | |
const string HtmlSkeleton = @"<html> | |
<head><title>Super Tabasco Example</title></head> | |
<body>{0}</body> | |
</html>"; | |
[Get] | |
public string Root() | |
{ | |
const string header = "<h1>Hello, Tabasco!</h1><br/>"; | |
const string form = @"<form method='post' action='/name'> | |
<label for='name'>What's your name?</label><br/> | |
<input type='text' name='name'/><br/><br/> | |
<input type='submit'/> | |
</form>"; | |
return string.Format(HtmlSkeleton, header + form); | |
} | |
[Post("/name")] | |
public string Name(IDictionary<string, string> data) | |
{ | |
var name = data["name"]; | |
var header = string.Format("<h1>Ahoy, {0}!</h1>", name); | |
var link = "<a href='/doctor?who='" + name + "'>Click to see your secret message.</a>"; | |
return string.Format(HtmlSkeleton, header + link); | |
} | |
[Get("/doctor")] | |
public dynamic[] Pepper(IDictionary<string, string> data) | |
{ | |
var who = data.ContainsKey("who") ? data["who"] : "you"; | |
return new dynamic[] | |
{ | |
200, | |
new Hash { { "Content-Type", "text/plain" } }, | |
"Wouldn't " + who + " like to be a pepper, too?" | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment