0

I have built a response wrapper as per alltej's answer shown in the below link:

How can I wrap Web API responses(in .net core) for consistency?

When a try to read the content of the response after the api call I get the following. The sample json is value in parameters.

response = await _apiClient.GetAsync("search/getParameter");
parameters = await response.Content.ReadAsStringAsync();

{"Version":"1.0","StatusCode":404,"ErrorMessage":"Request not found. The specified uri does not exist","Result":null} 

How can I make response.Content point to the "Result" in the JSON.

Am I missing something here?

2 Answers 2

2

You can try using AutoWrapper for Http response consistency, and use AutoWrapper.Server to unwrap the Result property at the server.

Sign up to request clarification or add additional context in comments.

2 Comments

is autowrapper compitable with xml output? I cant make it work if I want xml output
No. AutoWrapper does not support XML at the moment. Please submit a feature request so we can add support for it in the future versions.
0

By default, an ASP.NET Core app doesn't provide a status code page for HTTP status codes, such as 404 - Not Found. The app returns a status code and an empty response body.

You can customize that in your middleware like :

var readToEnd = new StreamReader(memoryStream).ReadToEnd();

if (context.Response.StatusCode == StatusCodes.Status404NotFound)
{
    readToEnd += "{ \"result\":\"Not Found\" }";
}

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.