Guilherme Ferreira
Guilherme Ferreira

Reputation: 1613

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?

Upvotes: 43

Views: 28495

Answers (2)

gi097
gi097

Reputation: 7701

It depends on what version of ASP.NET you are going to use. That can either be the .NET Core version or the traditional one.

As mentioned by Chris you can only use IActionResult in ASP.NET Core:

https://learn.microsoft.com/en-us/aspnet/core/web-api/action-return-types?view=aspnetcore-2.1#iactionresult-type

I'm creating an API

Well, if you are using the traditional ASP.NET - instead of .NET Core you are fine with using IHttpActionResult: https://learn.microsoft.com/en-us/aspnet/web-api/overview/getting-started-with-aspnet-web-api/action-results, otherwise stick with IActionResult.

Upvotes: 7

Chris Pratt
Chris Pratt

Reputation: 239430

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.

Upvotes: 59

Related Questions