What should be the return type of WEB API Action Method?

后端 未结 2 2136
时光取名叫无心
时光取名叫无心 2021-02-14 05:21

I am developing ASP.NET Web API using .NET Core. This Web API is going to be mainly accessed by UI application (UI will be developed using ASP.NET Core MVC) but in future API ma

2条回答
  •  情话喂你
    2021-02-14 05:57

    Have a look at swagger: https://docs.microsoft.com/en-us/aspnet/core/tutorials/web-api-help-pages-using-swagger It's better to specify ProducesResponseType attribute for method:

    [ProducesResponseType(typeof(TodoItem), 201)]
    public IActionResult Create([FromBody, Required] TodoItem item)
    

    So that automatically generated swagger documentation to show the actual returned data for the method.

提交回复
热议问题