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

原文:http://www.asp.net/web-api/overview/web-api-routing-and-actions/create-a-rest-api-with-attribute-routing

作为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})}")]
posted @   _DN  阅读(166)  评论(0编辑  收藏  举报
编辑推荐:
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· 智能桌面机器人:用.NET IoT库控制舵机并多方法播放表情
· Linux glibc自带哈希表的用例及性能测试
· 深入理解 Mybatis 分库分表执行原理
· 如何打造一个高并发系统?
阅读排行:
· Tinyfox 发生重大改版
· DeepSeek 全面指南,95% 的人都不知道的9个技巧(建议收藏)
· 对比使用DeepSeek与文新一言,了解DeepSeek的关键技术论文
· Brainfly: 用 C# 类型系统构建 Brainfuck 编译器
· DeepSeekV3+Roo Code,智能编码好助手
点击右上角即可分享
微信分享提示