I tried to understand both and write sample code:
public HttpResponseMessage Get()
{
var response = ControllerContext.Request
Assuming you want to unit test the responses, doesn't it make sense to always return an HttpResponseMessage? I don't particularly like the idea of returning a straight type from an ApiController since it doesn't follow typical development patterns.
In a non-Web API class that fetched a Customer, you'd likely return null, with your calling code checking for a null response:
public Customer GetCustomer(int id)
{
return db.Customers.Find(id);
}
But in Web API, you're not going to return null, you have to return something, even if that something is created after you throw an HttpResponseException. In that case, to ease testing, why not just always return an HttpResponseMessage, and make that your signature?
public HttpResponseMessage GetCustomer(int id)
{
var customer = db.Customers.Find(id);
if (customer == null)
{
return Request.CreateResponse(HttpStatusCode.NotFound);
}
return Request.CreateResponse(HttpStatusCode.OK, customer);
}