Skip to content

Instantly share code, notes, and snippets.

@jagregory
Created May 4, 2011 13:51
Show Gist options
  • Save jagregory/955248 to your computer and use it in GitHub Desktop.
Save jagregory/955248 to your computer and use it in GitHub Desktop.
Watch out NancyFX!
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>();
}
}
@jagregory
Copy link
Author

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.

@asbjornu
Copy link

asbjornu commented May 5, 2011

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.

@jagregory
Copy link
Author

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.

@asbjornu
Copy link

asbjornu commented May 5, 2011

Yea, I'm just nit-picking. You posted this on the Internet, after all:

;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment