Created
February 24, 2011 07:52
-
-
Save grumpydev/841897 to your computer and use it in GitHub Desktop.
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
namespace NancyConNegDemo | |
{ | |
using Extensions; | |
using Models; | |
using Nancy; | |
public class ConNegModule : NancyModule | |
{ | |
public ConNegModule() : base("/conneg") | |
{ | |
Get["/user/{id}"] = x => | |
{ | |
var model = database.GetUserById(x.id); | |
return I.RespondTo(ContentType.Html).WithView("UserView") | |
.RespondTo(ContentType.Json) | |
.RespondTo(ContentType.Xml) | |
.UsingModel(model) | |
.CacheFor(7).Days | |
.WithETag(hash); | |
}; | |
Get["/widget/{id}"] = x => | |
{ | |
var model = database.GetWidgetById(x.id); | |
return I.RespondToAll() | |
.Except(ContentType.Html) | |
.UsingModel(model); | |
}; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I'm not totally sure. Just thinking outloud, I'd probably rather handle this at the application level based on conventions I want for my application or model. I'm not sure I'd want to repeat all that .RespondTo stuff for every method.