Here are several benefits of IHttpActionResult
over HttpResponseMessage
mentioned in Microsoft ASP.Net Documentation:
- Simplifies unit testing your controllers.
- Moves common logic for creating HTTP responses into separate classes.
- Makes the intent of the controller action clearer, by hiding the low-level details of constructing the response.
But here are some other advantages of using IHttpActionResult
worth mentioning:
Ok
NotFound
Exception
Unauthorized
BadRequest
Conflict
Redirect
InvalidModelState
(link to full list)ExecuteAsync
method.ResponseMessageResult ResponseMessage(HttpResponseMessage response)
to convert HttpResponseMessage to IHttpActionResult.