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