Along similar lines to this question, is it okay to instantiate a client and hold on to it, or do I need to create a new instance for every call (or batch of calls)?
Whenever in doubt and if possible, look at the source code.
From a brief look it seems acceptable and even the better approach to hold on to a single instance, as it mainly responsible for executing IRestRequest
requests.
I was once in doubt with the same question regarding HttpClient
and found the following:
The default HttpClient is the simplest way in which you can start sending requests. A single HttpClient can be used to send as many HTTP requests as you want concurrently so in many scenarios you can just create one HttpClient and then use that for all your requests.
If concurrency is required, explore the source code to see if there may be any pitfalls. You can always default back to HttpClient
which is a part of the BCL since .NET 4.5 (and can be installed via NuGet on .NET 4.0)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With