Skip to content

RestClientOptions and its properties should have setters #2027

@konarx

Description

@konarx

It is related to changes that happened within the #1963 scope

Use case:
It is a common practice that the Authentication token is not provided during the initialization of the RestClient and has to be fetched later from a specific URI (eg. "/auth").

This was working in v108:

        _restClient = new RestClient("https://my-base-uri");

        var request = new RestRequest("auth")
            .AddJsonBody(new UserCredentials("user", "password123"));

        var response = await tempClient.PostAsync<LoginResponse>(request);
       
        _restClient.Authenticator = new JwtAuthenticator(response.Token);

This is a workaround in v109:

        //Creating a temporary RestClient only to perform a POST call to get the token
        var tempClient = new RestClient("https://my-base-uri");

        var request = new RestRequest("auth")
            .AddJsonBody(new UserCredentials("user", "password123"));
        
        var response = await tempClient.PostAsync<LoginResponse>(request);
           
        //In v109, the 'RestSharp.ReadOnlyRestClientOptions.Authenticator' has no setter.
        //For this case, a new instance of RestClient must be created
        _restClient = new RestClient(new RestClientOptions
           {
               BaseUrl = new Uri("https://my-base-uri"),
               Authenticator = new JwtAuthenticator(response.Token)
           });

Outcomes:
Instanciating 2 RestClient just to change one (or more) properties in Options is not optimal. My humble opinion is to create an instance of RestClient and to be able to change just the specific properties you may require.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions