Generic api base client
I'm trying to implement a generic api base client using
Polly
and System.Net.Http.Formatting
. I have this GetAsync<T>(string url)
function here
RestResponse just encapsulates the data and the statuscode and _retryPolicy
is an IAsyncPolicy
from Polly.
Now the question is: Could I somehow use this function when T is byte[]? If I do that in the current state, then I get an error, that the media type of the response data is application/pdf
and no MediaTypeFormatter exists for that.1 Reply
Ok, I stumbled upon a solution.
ReadAsAsync<T>
has an overload that accepts an IEnumerable<MediaTypeFormatters>
and an IFormatterLogger
. Then I wrote a custom media type formatter for byte[]
And that gives me the exact bytes as with ReadAsByteArrayAsync()