您的位置:首页 > 编程语言 > ASP

Create a REST API with Attribute Routing in ASP.NET Web API 2

2016-09-03 00:18 459 查看
原文:http://www.asp.net/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

作为Restful API设计的一个参考,将其记录下来。

控制器上设添加属性:

RoutePrefix("/api/books")

ActionExample URICode
Get a list of all books./api/booksRoute("")
Get a book by ID./api/books/1Route("{id:int}")
Get the details of a book./api/books/1/detailsRoute("{id:int}/details")
Get a list of books by genre./api/books/fantasyRoute("{genre}")
Get a list of books by a particular author./api/authors/1/booksRoute("~/api/authors/{id:int}/books")
Get a list of books by publication date./api/books/date/2013-02-16[Route("date/{pubdate:datetime:regex(\d{4}-\d{2}-\d{2})}")]
Get a list of books by publication/api/books/date/2013/02/16 (alternate form)[Route("date/{*pubdate:datetime:regex(\d{4}/\d{2}/\d{2})}")]
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: