Skip to content

Instantly share code, notes, and snippets.

@jayhjkwon
Last active December 20, 2015 05:19
Show Gist options
  • Save jayhjkwon/6077757 to your computer and use it in GitHub Desktop.
Save jayhjkwon/6077757 to your computer and use it in GitHub Desktop.
WebAPI attribute routing
[RoutePrefix("api/books")]
public class BooksController : ApiController
{
// GET api/books
[Route("")]
public IEnumerable<Book> Get() { ... }
// GET api/books/5
[Route("{id:int}")]
public Book Get(int id) { ... }
// POST api/books
[Route("")]
public HttpResponseMessage Post(Book book) { ... }
}
public static class WebApiConfig
{
public static void Register(HttpConfiguration config)
{
config.MapHttpAttributeRoutes();
}
}
@richheey
Copy link

test

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