Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Possibility to set Serializer on RestRequest (instead of client), for client reuse with different serialisers #2070

Open
unhammer opened this issue Apr 24, 2023 · 3 comments

Comments

@unhammer
Copy link

Is your feature request related to a problem? Please describe.

I'd like to reuse RestClient for different requests, from different threads. I'd also like to have different serialisers per request (mainly for logging of url along with exact response). I can easily have one of these, but currently not both at the same time, since the serialiser is set on the client, not on the request.

Describe the solution you'd like
I would like to do

                 private static RestClient client;var req = new RestRequest(url);
                 req.UseSerializer(() => new MySerializer(myargs);

(or var req = new RestRequest(url, serializer: …);) instead of having to

                var req = new RestRequest(url);
                client = new RestClient();
                client.UseSerializer(() => new MySerializer(myargs);

Describe alternatives you've considered
There is #1791 (comment) which created a whole dictionary of clients to workaround the issue. I would end up with too many clients to use this workaround – preferably I'd have just one client for all requests.

Additional context

https://restsharp.dev/v107/#restclient-lifecycle says we should reuse, as with HttpClient :)

@alexeyzimarev
Copy link
Member

Btw logging the response is better handled by adding a delegating handler to the message handler by using options.ConfigureMessageHandler.

#2026 (comment)

@alexeyzimarev
Copy link
Member

There is also a callback OnBeforeDeserialization on the request level that gives you the RestResponse instance before it is sent to deserialiser.

@kendallb
Copy link
Contributor

I like the idea of allowing the serializer to be set on the request.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants