Version 1, last updated by Andrew Davey at May 28 07:54 2009 UTC
Action Methods
Requirements
An action method needs two things to work with Snooze:
- The name must be an HTTP verb i.e. Get, Put, Post, Delete
- The first parameter must be a Url type.
You can have additional parameters after the Url. Everything is bound using the usual MVC model binders.
Return Type
Snooze actions can work just like ordinary MVC actions, your can return an ActionResult that will be executed by the infrastructure. So you can keep using the View and Json methods if needed. However, it's much nicer to use the HTTP status code methods. For example:
public ActionResult Get(CustomerUrl url)
{
var viewModel = CreateCustomerViewModel(url.CustomerId);
return OK(viewModel);
}
The result will be a ResourceResult object and have the OK status code, but you could use others like NotFound, SeeOther, BadRequest, NotModified, etc. Status codes are important in REST, so make use of them!
Also note that this approach doesn't bind the action method to a particular resource representation. ResourceResult will determine what representation the requesting client (web browser/ajax call) would like. So your ajax call will get JSON and your web browser will get HTML, for example. Snooze also has support for XML and plain text formatting.
View Engine Support
For HTML requests snooze will use the MVC ViewEngine infrastructure.
The view name will equal the type name of the view model, minus the "ViewModel" or "Model" extensions. So "CustomerViewModel" will require a view called "Customer".