Skip to content

Instantly share code, notes, and snippets.

@hagbarddenstore
Created August 7, 2013 12:56
Show Gist options
  • Save hagbarddenstore/6173801 to your computer and use it in GitHub Desktop.
Save hagbarddenstore/6173801 to your computer and use it in GitHub Desktop.
// Controller
public class ValuesController : ApiController
{
public IEnumerable<string> FindAll()
{
}
public string FindOneById(int id)
{
}
public string FindOneByLicense(string license)
{
}
public void Post([FromBody]string value)
{
}
public void Put(int id, [FromBody]string value)
{
}
public void Delete(int id)
{
}
}
// Route configuration
routes.MapRoute("Values.FindAll", "api/values", new { controller = "Values", action = "FindAll" }, new { httpMethod = new HttpMethodConstraint("GET") });
routes.MapRoute("Values.Post", "api/values", new { controller = "Values", action = "Post" }, new { httpMethod = new HttpMethodConstraint("POST") });
routes.MapRoute("Values.FindOneById", "api/values/{id}", new { controller = "Values", action = "FindOneById" }, new { httpMethod = new HttpMethodConstraint("GET"), id = "\\d+" });
routes.MapRoute("Values.Put", "api/values/{id}", new { controller = "Values", action = "Put" }, new { httpMethod = new HttpMethodConstraint("PUT"), id = "\\d+" });
routes.MapRoute("Values.Delete", "api/values/{id}", new { controller = "Values", action = "Delete" }, new { httpMethod = new HttpMethodConstraint("DELETE"), id = "\\d+" });
routes.MapRoute("Values.FindOneByLicense", "api/values/{license}", new { controller = "Values", action = "FindOneByLicense" }, new { httpMethod = new HttpMethodConstraint("GET"), license = "\\w+" });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment