Created
May 4, 2011 13:51
-
-
Save jagregory/955248 to your computer and use it in GitHub Desktop.
Watch out NancyFX!
This file contains 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
public class Api : Restish | |
{ | |
Api() | |
{ | |
Get("/customers", (req, res) => | |
{ | |
return View(new[] | |
{ | |
new { name = "Charles" } | |
}); | |
}); | |
Post("/customers", (req, res) => | |
{ | |
// save customers here | |
return Redirect("/customers"); | |
}).WithFilter<Authorize>(); | |
Delete("/customers/{id}", (req, res) => | |
{ | |
// delete customer here | |
return Redirect("/customers"); | |
}).WithFilter<Authorize>(); | |
} | |
} |
Doing a redirect after saving a customer isn't 100% kosher. A more correct status code (than the 301 you respond with through your redirect) to receive after a successful POST is "201 Created". The same goes for the redirect after DELETE; it should return "200 OK". See RFC 5023 for inspiration.
I am familiar with rest :)
This was a 5 minute hack to see if I could get it working on top of MVC1, with an even quicker example, not a example of a good rest api.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
An exercise to see if I could twist MVC (1 in this case) to work more like Sinatra/Node without sacrificing MVC's built in features (filters etc...). Seems to work so far.