ValuesController.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283
  1. using System.Collections.Generic;
  2. using System.Threading;
  3. using System.Threading.Tasks;
  4. using Microsoft.AspNetCore.Http.Features;
  5. using Microsoft.AspNetCore.Mvc;
  6. namespace Did.Serslot.Demo.Controllers
  7. {
  8. [Route("did_serslot/[controller]")]
  9. [Route("did_serslot/v1")]
  10. [ApiController]
  11. public class ValuesController : ControllerBase
  12. {
  13. #region (x.1)route
  14. /// <summary>
  15. /// GET did_serslot/Values
  16. /// </summary>
  17. /// <returns></returns>
  18. [HttpGet]
  19. public object Route0([FromQuery]string a)
  20. {
  21. //var requestFeature = Request.HttpContext.Features.Get<IHttpRequestFeature>();
  22. return "GET did_serslot/Values?a=" + a;
  23. }
  24. /// <summary>
  25. /// GET did_serslot/Values/route_x
  26. /// </summary>
  27. /// <returns></returns>
  28. [HttpGet("route1")]
  29. [HttpGet("route2")]
  30. [HttpGet("/did_serslot/Values/route3")]
  31. public object Route1()
  32. {
  33. return new
  34. {
  35. Request.Path,
  36. Method = Request.Method
  37. };
  38. }
  39. /// <summary>
  40. /// GET did_serslot/Values/route4
  41. /// </summary>
  42. /// <returns></returns>
  43. [HttpGet("[action]")]
  44. public object route4()
  45. {
  46. return new
  47. {
  48. name = "GET did_serslot/Values/route4",
  49. Request.Path,
  50. Method = Request.Method
  51. };
  52. }
  53. #endregion
  54. #region (x.2) result
  55. /// <summary>
  56. /// GET did_serslot/Values/result1
  57. /// </summary>
  58. /// <returns></returns>
  59. [HttpGet("result1")]
  60. public object Result1()
  61. {
  62. return "GET did_serslot/Values/result1";
  63. }
  64. /// <summary>
  65. /// GET did_serslot/Values/result2
  66. /// </summary>
  67. /// <returns></returns>
  68. [HttpGet("result2")]
  69. public ActionResult<string> Result2()
  70. {
  71. return "GET did_serslot/Values/result2";
  72. }
  73. /// <summary>
  74. /// GET did_serslot/Values/result3
  75. /// </summary>
  76. /// <returns></returns>
  77. [HttpGet("result3")]
  78. public ActionResult<IEnumerable<string>> Result3()
  79. {
  80. return new string[] { "GET did_serslot/Values/result3", "" };
  81. }
  82. /// <summary>
  83. /// GET did_serslot/Values/result4
  84. /// </summary>
  85. /// <returns></returns>
  86. [HttpGet("result4")]
  87. public async Task<string> Result4()
  88. {
  89. await Task.Run(() => { Thread.Sleep(2000); });
  90. return "GET did_serslot/Values/result4";
  91. }
  92. /// <summary>
  93. /// GET did_serslot/Values/result5
  94. /// </summary>
  95. /// <returns></returns>
  96. [HttpGet("result5")]
  97. public async Task<ActionResult<string>> Result5()
  98. {
  99. await Task.Run(() => { Thread.Sleep(2000); });
  100. return "GET did_serslot/Values/result5";
  101. }
  102. #endregion
  103. #region (x.3) HttpMethod
  104. /// <summary>
  105. /// GET did_serslot/Values/method
  106. /// </summary>
  107. /// <returns></returns>
  108. [HttpGet("method")]
  109. public string Method_Get()
  110. {
  111. return "GET did_serslot/Values/method";
  112. }
  113. /// <summary>
  114. /// POST did_serslot/Values/method
  115. /// </summary>
  116. /// <returns></returns>
  117. [HttpPost("method")]
  118. public string Method_Post()
  119. {
  120. return "POST did_serslot/Values/method";
  121. }
  122. /// <summary>
  123. /// Put did_serslot/Values/method
  124. /// </summary>
  125. /// <returns></returns>
  126. [HttpPut("method")]
  127. public string Method_Put()
  128. {
  129. return "Put did_serslot/Values/method";
  130. }
  131. /// <summary>
  132. /// Delete did_serslot/Values/method
  133. /// </summary>
  134. /// <returns></returns>
  135. [HttpDelete("method")]
  136. public string Method_Delete()
  137. {
  138. return "Delete did_serslot/Values/method";
  139. }
  140. /// <summary>
  141. /// Head did_serslot/Values/method
  142. /// </summary>
  143. /// <returns></returns>
  144. [HttpHead("method")]
  145. public string Method_Head()
  146. {
  147. return "Head did_serslot/Values/method";
  148. }
  149. /// <summary>
  150. /// Options did_serslot/Values/method
  151. /// </summary>
  152. /// <returns></returns>
  153. [HttpOptions("method")]
  154. public string Method_Options()
  155. {
  156. return "Options did_serslot/Values/method";
  157. }
  158. /// <summary>
  159. /// Patch did_serslot/Values/method
  160. /// </summary>
  161. /// <returns></returns>
  162. [HttpPatch("method")]
  163. public string Method_Patch()
  164. {
  165. return "Patch did_serslot/Values/method";
  166. }
  167. /// <summary>
  168. /// get|post did_serslot/Values/method2
  169. /// </summary>
  170. /// <returns></returns>
  171. [Route("method2")]
  172. [HttpGet, HttpPost]
  173. public object Method2()
  174. {
  175. return new
  176. {
  177. Request.Path,
  178. Method = Request.Method
  179. };
  180. }
  181. #endregion
  182. #region (x.4) Arg
  183. /// <summary>
  184. /// GET did_serslot/Values/arg1/{id}/{id2}
  185. /// </summary>
  186. /// <returns></returns>
  187. [HttpGet("arg1/{id}/{id2}")]
  188. public object Arg1(string id, string id2)
  189. {
  190. return new
  191. {
  192. route = "GET did_serslot/Values/arg1/{id}/{id2}",
  193. arg = new { id, id2 }
  194. };
  195. }
  196. ///// <summary>
  197. ///// GET did_serslot/Values/arg2/arg2?id={id}
  198. ///// </summary>
  199. ///// <returns></returns>
  200. //[HttpGet("arg2?id={id}")]
  201. //public object Arg2(string id)
  202. //{
  203. // return new
  204. // {
  205. // route = "GET did_serslot/Values/arg2/arg2?id={id}",
  206. // arg = new { id }
  207. // };
  208. //}
  209. /// <summary>
  210. /// POST did_serslot/Values/arg3
  211. /// </summary>
  212. /// <returns></returns>
  213. [HttpPost("arg3")]
  214. public object Arg3([FromBody] string arg1)
  215. {
  216. return new
  217. {
  218. route = "POST did_serslot/Values/arg3",
  219. arg = new { arg1 }
  220. };
  221. }
  222. /// <summary>
  223. /// POST did_serslot/Values/arg4
  224. /// </summary>
  225. /// <returns></returns>
  226. [HttpPost("arg4")]
  227. public object Arg4([FromBody] Arg4Model arg)
  228. {
  229. return new
  230. {
  231. route = "POST did_serslot/Values/arg4",
  232. arg = arg
  233. };
  234. }
  235. public class Arg4Model
  236. {
  237. public string arg1 { get; set; }
  238. public string arg2 { get; set; }
  239. };
  240. #endregion
  241. }
  242. }