The Web API basically return 4 type of object: void
, HttpResponseMessage
, IHttpActionResult
, and other strong types. The first version of the Web API returns HttpResponseMessage
which is pretty straight forward HTTP response message.
The IHttpActionResult
was introduced by WebAPI 2 which is a kind of wrap of HttpResponseMessage
. It contains the ExecuteAsync()
method to create an HttpResponseMessage
. It simplifies unit testing of your controller.
Other return type are kind of strong typed classes serialized by the Web API using a media formatter into the response body. The drawback was you cannot directly return an error code such as a 404. All you can do is throwing an HttpResponseException
error.