using System.Collections.Generic; using System.Threading; using System.Threading.Tasks; using Microsoft.AspNetCore.Mvc; namespace Did.NetcoreLoader.Demo.Controllers { [Route("apidemo/[controller]")] [Route("apidemo/v1")] [ApiController] public class ValuesController : ControllerBase { #region (x.1)route /// /// GET apidemo/Values /// /// [HttpGet] public object Route0() { //var requestFeature = Request.HttpContext.Features.Get(); return "GET apidemo/Values"; } /// /// GET apidemo/Values/route_x /// /// [HttpGet("route1")] [HttpGet("route2")] [HttpGet("/apidemo/Values/route3")] public object Route1() { return new{ Request.Path, Method = Request.Method }; } /// /// GET apidemo/Values/route4 /// /// [HttpGet("[action]")] public object route4() { return new { name= "GET apidemo/Values/route4", Request.Path, Method = Request.Method }; } #endregion #region (x.2) result /// /// GET apidemo/Values/result1 /// /// [HttpGet("result1")] public object Result1() { return "GET apidemo/Values/result1"; } /// /// GET apidemo/Values/result2 /// /// [HttpGet("result2")] public ActionResult Result2() { return "GET apidemo/Values/result2"; } /// /// GET apidemo/Values/result3 /// /// [HttpGet("result3")] public ActionResult> Result3() { return new string[] { "GET apidemo/Values/result3", "" }; } /// /// GET apidemo/Values/result4 /// /// [HttpGet("result4")] public async Task Result4() { await Task.Run(() => { Thread.Sleep(2000); }); return "GET apidemo/Values/result4"; } /// /// GET apidemo/Values/result5 /// /// [HttpGet("result5")] public async Task> Result5() { await Task.Run(() => { Thread.Sleep(2000); }); return "GET apidemo/Values/result5"; } #endregion #region (x.3) HttpMethod /// /// GET apidemo/Values/method /// /// [HttpGet("method")] public string Method_Get() { return "GET apidemo/Values/method"; } /// /// POST apidemo/Values/method /// /// [HttpPost("method")] public string Method_Post() { return "POST apidemo/Values/method"; } /// /// Put apidemo/Values/method /// /// [HttpPut("method")] public string Method_Put() { return "Put apidemo/Values/method"; } /// /// Delete apidemo/Values/method /// /// [HttpDelete("method")] public string Method_Delete() { return "Delete apidemo/Values/method"; } /// /// Head apidemo/Values/method /// /// [HttpHead("method")] public string Method_Head() { return "Head apidemo/Values/method"; } /// /// Options apidemo/Values/method /// /// [HttpOptions("method")] public string Method_Options() { return "Options apidemo/Values/method"; } /// /// Patch apidemo/Values/method /// /// [HttpPatch("method")] public string Method_Patch() { return "Patch apidemo/Values/method"; } /// /// get|post apidemo/Values/method2 /// /// [Route("method2")] [HttpGet,HttpPost] public object Method2() { return new { Request.Path, Method = Request.Method }; } #endregion #region (x.4) Arg /// /// GET apidemo/Values/arg1/{id}/{id2} /// /// [HttpGet("arg1/{id}/{id2}")] public object Arg1(string id,string id2) { return new { route= "GET apidemo/Values/arg1/{id}/{id2}", arg = new { id,id2 } }; } ///// ///// GET apidemo/Values/arg2/arg2?id={id} ///// ///// //[HttpGet("arg2?id={id}")] //public object Arg2(string id) //{ // return new // { // route = "GET apidemo/Values/arg2/arg2?id={id}", // arg = new { id } // }; //} /// /// POST apidemo/Values/arg3 /// /// [HttpPost("arg3")] public object Arg3([FromBody] string arg1) { return new { route = "POST apidemo/Values/arg3", arg = new { arg1 } }; } /// /// POST apidemo/Values/arg4 /// /// [HttpPost("arg4")] public object Arg4([FromBody] Arg4Model arg) { return new { route = "POST apidemo/Values/arg4", arg = arg }; } public class Arg4Model { public string arg1 { get; set; } public string arg2 { get; set; } }; #endregion } }