Last active
December 20, 2015 05:19
-
-
Save jayhjkwon/6077757 to your computer and use it in GitHub Desktop.
WebAPI attribute routing
This file contains hidden or 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
[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) { ... } | |
} |
This file contains hidden or 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 static class WebApiConfig | |
{ | |
public static void Register(HttpConfiguration config) | |
{ | |
config.MapHttpAttributeRoutes(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
test