Return HttpResponseMessage in Net5 Api

Viewed 555

I am in the process of updating a web api from netcore 2.2 to .net5 I have a lot of endpoints setup to create a new request to another endpoint and directly return that response

[HttpGet]
public async Task<HttpResponseMessage> TemplateJobs(DateTime? syncDate = null)
{
    string requestUrl = $"/api/job/template?syncStamp={syncDate}";
    return await GetRequestAsync(requestUrl);
}

Where "GetRequestAsync", does some token verification and creates a request and sends it via httpclient and returns the HttpResponseMessage

However now on .net5 the HttpResponseMessage seems to be getting packaged into another httpresponse so when I test the endpoint in postman the response I get is this, rather than the object list im expecting

{
    "version": {
        "major": 1,
        "minor": 1,
        "build": -1,
        "revision": -1,
        "majorRevision": -1,
        "minorRevision": -1
    },
    "content": {
        "headers": [
            {
                "key": "Content-Type",
                "value": [
                    "application/json; charset=utf-8"
                ]
            }
        ]
    },
    "statusCode": 200,
    "reasonPhrase": "OK",
    "headers": [],
    "trailingHeaders": [],
    "requestMessage": null,
    "isSuccessStatusCode": true
}

I have read this SO post here which says to read the response and create an IAction response from the request, this seems like a hack and not the correct way to do it.

Is there a way to just return an HttpResponseMessage directly without unpacking and repacking it

0 Answers
Related