提问
标准的WebApi应该有哪些元素
回答
- 声明完整的响应码200,404,401,400
- 添加Operation
- 添加Tag聚合业务
- 申明请求和响应类型
- 标注参数来源FromHeader
- 使用IActionResult代替ActionResult
[Tag("查询类服务")]
[HttpGet, Route("mytoute", Name = nameof(GetSomething))]
[ProducesResponseType((int)HttpStatusCode.OK, Type = typeof([数据类型]))]
[ProducesResponseType((int)HttpStatusCode.NotFound, Type = typeof(string))]
public IActionResult GetSomething([FromQuery] string va,[FromHeader(Name = "access_token")]string token)
{
//TODO
if (OK)
return Ok([结果]);
return NotFound("没找到");
}
标签:WebApi,return,IActionResult,ProducesResponseType,哪些,int,元素,string
From: https://www.cnblogs.com/wuhailong/p/17321065.html