Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion Xablu.WebApiClient/IRestApiClient.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Threading;
using System.Threading.Tasks;
Expand Down Expand Up @@ -49,5 +49,8 @@ Task<IRestApiResult<TResult>> DeleteAsync<TResult>(
IList<KeyValuePair<string, string>> headers = null,
IHttpResponseResolver httpResponseResolver = null,
CancellationToken cancellationToken = default(CancellationToken));

void ConfigureOptions(RestApiClientOptions options);
void ChangeBaseAddress(string newBaseAdress);
}
}
14 changes: 12 additions & 2 deletions Xablu.WebApiClient/RestApiClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Xablu.WebApiClient
public class RestApiClient
: IRestApiClient
{
private readonly RestApiClientOptions _restApiClientOptions;
private RestApiClientOptions _restApiClientOptions;

private bool _isDisposed;
private Lazy<HttpClient> _explicit;
Expand All @@ -23,14 +23,24 @@ public class RestApiClient
public RestApiClient(string apiBaseAddress)
{
_restApiClientOptions = new RestApiClientOptions(apiBaseAddress);

Initialize();
}

public RestApiClient(RestApiClientOptions options)
{
_restApiClientOptions = options ?? throw new ArgumentNullException(nameof(options));
Initialize();
}

public void ConfigureOptions(RestApiClientOptions options)
{
_restApiClientOptions = options;
Initialize();
}

public void ChangeBaseAddress(string newBaseAdress)
{
_restApiClientOptions.ApiBaseAddress = newBaseAdress;
Initialize();
}

Expand Down
4 changes: 2 additions & 2 deletions Xablu.WebApiClient/RestApiClientOptions.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using Newtonsoft.Json;
using System.Collections.Generic;
using Xablu.WebApiClient.Resolvers;
using System.Net.Http;
Expand All @@ -21,7 +21,7 @@ public RestApiClientOptions(string apiBaseAddress)
/// An example could be "https://www.xablu.com". The base address will be appended in front of the 'path' value which
/// is supplied with every HTTP request.
/// </remarks>
public string ApiBaseAddress { get; }
public string ApiBaseAddress { get; set; }

/// <summary>
/// Gets or sets a delegate which will instantiate an instance of <see cref="HttpMessageHandler"/> class used to process the HTTP requests.
Expand Down