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?

Atish Jadhav
  • 61
  • 1
  • 2
  • 4

2 Answers2

2

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

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\" }";
}
Nan Yu
  • 26,101
  • 9
  • 68
  • 148