Reputation: 1613
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
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
:
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
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