Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IHttpActionResult vs IActionResult

I'm creating an API using .NET Core 2 to provide data for many applications developed in different technologies. I'm currently returning IActionresult from my methods. I've been studying what the best option is to return the data and saw some examples using IHttpActionResult. Now I dont't know which type is the best to return.

What is the difference between IHttpActionResult and IActionresult?

like image 734
Guilherme Ferreira Avatar asked Jul 23 '18 14:07

Guilherme Ferreira


People also ask

What is the difference between IHttpActionResult and IActionResult?

What is the difference between IHttpActionResult and IActionresult ? "IActionResult is the new abstraction that should be used in your actions. Since Web API and MVC frameworks have been unified in ASP.NET Core, various IActionResult implementations can handle both traditional API scenarios.".

What is difference between IHttpActionResult and HttpResponseMessage?

IHttpActionResult contains a single method, ExecuteAsync, which asynchronously creates an HttpResponseMessage instance. If a controller action returns an IHttpActionResult, Web API calls the ExecuteAsync method to create an HttpResponseMessage. Then it converts the HttpResponseMessage into an HTTP response message.

What is IHttpActionResult in Web API?

The IHttpActionResult interface is contained in the System. Web. Http namespace and creates an instance of HttpResponseMessage asynchronously. The IHttpActionResult comprises a collection of custom in-built responses that include: Ok, BadRequest, Exception, Conflict, Redirect, NotFound, and Unauthorized.

What does IActionResult mean?

The IActionResult return type is appropriate when multiple ActionResult return types are possible in an action. The ActionResult types represent various HTTP status codes. Any non-abstract class deriving from ActionResult qualifies as a valid return type.


1 Answers

IHttpActionResult is for ASP.NET Web Api, while IActionResult is for ASP.NET Core. There's no such thing as "Web Api" in ASP.NET Core. It's all just "Core". However, some people still refer to creating an ASP.NET Core API as a "Web Api", which adds to the confusion.

like image 102
Chris Pratt Avatar answered Sep 18 '22 14:09

Chris Pratt