You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I've got an API that returns { data: [], statusCode: <int>, error: "" }
When I call
[Get("/api/data")]Task<ApiResponse<T>>GetData();
I would like T in this case to a custom type that would refer to data; statusCode to map to Refit.ApiResponse's StatusCode; and error to be mapped to Refit.ApiResponse's ReasonPhrase.
Is this at all possible? I understand that you can provide custom JSON serializers that can partially handle this, but I know not of a way that I can get ApiResponse.StatusCode, and ApiResponse.ReasonPhrase to reflect my API's statusCode and error, respectively.
I'm starting to think that Refit's ApiResponse class was not designed for this purpose, and I am better off just using a bespoke ApiResponse type (which is what I'm currently doing) - but I am trying to reduce code repetition for something which may already be available to me!
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Hi.
I've got an API that returns
{ data: [], statusCode: <int>, error: "" }When I call
I would like
Tin this case to a custom type that would refer todata;statusCodeto map toRefit.ApiResponse'sStatusCode; anderrorto be mapped toRefit.ApiResponse'sReasonPhrase.Is this at all possible? I understand that you can provide custom JSON serializers that can partially handle this, but I know not of a way that I can get
ApiResponse.StatusCode, andApiResponse.ReasonPhraseto reflect my API'sstatusCodeanderror, respectively.I'm starting to think that Refit's ApiResponse class was not designed for this purpose, and I am better off just using a bespoke ApiResponse type (which is what I'm currently doing) - but I am trying to reduce code repetition for something which may already be available to me!
Thanks.
Beta Was this translation helpful? Give feedback.
All reactions