Search code examples
restsharp

Can we re-use a RestClient for calling different TCP endpoints?


The documentation at https://restsharp.dev/v107/#recommended-usage says:

Do not use one instance of RestClient across different API clients.

Our use-case is calling callback URLs received in requests from a client and it looks like re-using a single RestClient for calling different TCP endpoints in this case works just fine with HttpClient's connection pooling handling multiple connections properly.

So I'm wondering if I'm missing something or just reading it wrong.


Solution

  • The suggestion for not using one RestClient instance for different API endpoints is based on the fact that different endpoints might require different configuration, like serialisation formats, authorisation, default headers, cookie handling, etc.

    Technically, there's no impediment for reusing a single instance between different APIs. In fact, RestClient doesn't require the BaseUrl to be provided when constructing the client, and each request might have a full absolute URI.