I am an experienced programmer but new to WebApi (We're using MS asp.net mvc framework).
A customer requested that all return values be wrapped in an object of this sort:
{
success: [boolean],
errorLog: [error message, if failed],
referer: [api call details],
payload: {
// results, if success
}
I saw that the standard already called for returning an HttpResponseMessage object, which has this information. So, rather than duplicating, I just return an object of this type (either directly, or via an IHttpActionResult, e.g.
return Ok(object);
However, I cannot see how to use this object from the client side. When I make an api call from the browser, all I see is the content (even using the debugger). When I return an error, I see:
<Error>
<Message>foo bar</Message>
</Error>
but no sign of the other info (StatusCode, ReasonPhrase, etc.). The same applies if I return Json format.
Is this object 'stripped' somewhere along the line, and if so by who? How can I allow this object to arrive to the api caller so s/he can use all the associated fields?
Thanks
Edit: As requested by comment, I'm posting my server-side code, though there isn't much to it. My attempt at seeing the HttpResponseMessage object was to create this controller:
public HttpResponseMessage Get() {
HttpResponseMessage response = Request.CreateErrorResponse(HttpStatusCode.NotAcceptable, "foo bar");
response.ReasonPhrase = "There is no reason.";
return response;
}
This is the code which results in the xml posted above.