I'm using a generic return type for all my api responses:
public HttpStatusCode statusCode { get; set; }
public string error { get; set; }
public IDictionary<string, string> errorfor { get; set; }
public T result { get; set; }
and in API:
/// <summary>
/// GET Order API
/// </summary>
/// <returns> return list of orders {Order} </returns>
public HttpResponseMessage Get(){
var response = new BaseResponseMessage<IList<Order>>();
//some more codes
response.result = orders;
return Request.CreateResponse(HttpStatusCode.OK, response);
}
Now of course my API Help page don't show Order in sample Response body. Is it possible to configure Help Page generator to show generic type? Thanks!
Specific Type as the Return type in ASP.NET Core Web API. We can return any type of primitive data like string, integer, Boolean, etc., or complex data like Employee, Product, etc, directly from the controller action method. Returning String from ASP.NET Core Web API Controller Action Method:
The ASP.NET Core 2.1 introduced the ActionResult<T> return type for the Web API controller action methods. It enables us to return a type deriving either from ActionResult or return a specific type. Let us understand this with an example.
You could create all of the documentation manually, but it is better to autogenerate as much as possible. To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template.
To make this task easier, ASP.NET Web API provides a library for auto-generating help pages at run time. Install ASP.NET and Web Tools 2012.2 Update. This update integrates help pages into the Web API project template. Next, create a new ASP.NET MVC 4 project and select the Web API project template.
Web API 2.1 Help Pages now do this: http://www.asp.net/web-api/overview/releases/whats-new-in-aspnet-web-api-21#help-page
You might also check out returning the standard HttpResponseMessage with the new ResponseTypeAttribute:
/// <summary>
/// GET Order API
/// </summary>
[ResponseType(typeof(List<Order>))]
public HttpResponseMessage Get()
{
var orders = new List<Order>();
return Request.CreateResponse(HttpStatusCode.OK, orders);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With