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")
作为Restful API设计的一个参考,将其记录下来。
控制器上设添加属性:
RoutePrefix("/api/books")
Action | Example URI | Code |
---|---|---|
Get a list of all books. | /api/books | Route("") |
Get a book by ID. | /api/books/1 | Route("{id:int}") |
Get the details of a book. | /api/books/1/details | Route("{id:int}/details") |
Get a list of books by genre. | /api/books/fantasy | Route("{genre}") |
Get a list of books by a particular author. | /api/authors/1/books | Route("~/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})}")] |
相关文章推荐
- ASP.NET MVC – Create easy REST API with JSON and XML(转)
- Attribute Routing in ASP.NET Web API 2
- Replace JSON.NET with ServiceStack.Text in ASP.NET Web API
- ASP.NET Web API与Rest web api(一)
- Asp.Net Web API 2第十八课——Working with Entity Relations in OData
- ASP.NET Web API 2 external logins with Facebook and Google in AngularJS app
- ASP.Net Web API 输出缓存 转载 -- Output caching in ASP.NET Web API
- File Upload using jQuery AJAX in ASP.NET Web API or Http handler (AJAX上传文件通过Web API或 http handler)
- Asp.Net Web API 2第十八课——Working with Entity Relations in OData
- ASP.NET Web API与Rest web api(一)
- Asp.Net Web API 2第十八课——Working with Entity Relations in OData
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【九】——API变了,客户端怎么办?
- Create XML with LoadXml(string) in ASP.NET
- ASP.NET MVC #01, Create a Movie Database Application in 15 Minutes with ASP.NET MVC
- 使用ASP.NET Web Api构建基于REST风格的服务实战系列教程【九】——API变了,客户端怎么办?
- Replace JSON.NET with Jil JSON serializer in ASP.NET Web API
- [转]Getting started with ASP.NET Web API OData in 3 simple steps
- Attribute Routing in ASP.NET MVC 5
- Routing in ASP.NET Web API
- [转]How do you create a custom AuthorizeAttribute in ASP.NET Core?