So I've seen the Web API 2 Controllers return HttpResponse
and the actual object. Example:
public HttpResponseMessage Get(string id)
{
var app = apps.Single(c => c.Id == id);
return new HttpResponseMessage(HttpStatusCode.OK)
{
Content = new ObjectContent<object>(app,
Configuration.Formatters.JsonFormatter)
};
}
or
public Application Get(string id)
{
return apps.Single(c => c.Id == id);
}
My question which is the 'right' way? #2 is much shorter but is it better to do #1 or does #2 do #1 automatically ... ?