Skip to content

csharp: Mark BaseUrl as deprecated in favor of ServerUrl on SvixOptions #1917

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

Merged
merged 6 commits into from
May 6, 2025
Merged
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
1 change: 1 addition & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Libs/Python: Bring back the (deprecated) sync `dashboard_access` method, which was accidentally
removed in v1.64.1
* Libs/Csharp: The `options` argument to the `SvixClient` initializer is now optional.
* Libs/Csharp: The `SvixOptions.BaseUrl` field is deprecated in favor of `SvixOptions.ServerUrl`

## Version 1.64.1
* Libs/JavaScript: Add `HTTPValidationError`, `HttpErrorOut`, `ValidationError` and `ApiException` to the top level exports.
Expand Down
6 changes: 4 additions & 2 deletions csharp/Svix/SvixClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,14 @@ public SvixClient(
)
{
Logger = logger;
var opts = options ?? new SvixOptions(Utils.DefaultServerUrlFromToken(token));
SvixHttpClient =
svixHttpClient
?? new SvixHttpClient(
token,
options ?? new SvixOptions(Utils.DefaultServerUrlFromToken(token)),
$"svix-libs/{Version.version}/csharp"
opts.RetryScheduleMilliseconds,
$"svix-libs/{Version.version}/csharp",
opts.ServerUrl ?? Utils.DEFAULT_SERVER_URL
);
}
}
Expand Down
21 changes: 14 additions & 7 deletions csharp/Svix/SvixHttpClient.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using System.Net;
using System.Collections.Generic;
using System.Net;
using System.Net.Http.Headers;
using System.Text;
using Newtonsoft.Json;

namespace Svix
{
public class SvixHttpClient(string token, SvixOptions options, string userAgent)
public class SvixHttpClient(
string token,
List<int> retryScheduleMilliseconds,
string userAgent,
string serverUrl
)
{
readonly SvixOptions _options = options;
readonly HttpClient _httpClient = new();
private readonly List<int> retryScheduleMilliseconds = retryScheduleMilliseconds;
private readonly string serverUrl = serverUrl;
private readonly HttpClient _httpClient = new();
private readonly string _token = token;
private readonly JsonSerializerSettings patchJsonOptions = new();
private readonly JsonSerializerSettings JsonOptions = new()
Expand Down Expand Up @@ -63,13 +70,13 @@ public async Task<ApiResponse<T>> SendRequestAsync<T>(
content
);
var response = await _httpClient.SendAsync(request, cancellationToken);
for (var index = 0; index < _options.RetryScheduleMilliseconds.Count; index++)
for (var index = 0; index < retryScheduleMilliseconds.Count; index++)
{
if ((int)response.StatusCode < 500)
{
break;
}
Thread.Sleep(_options.RetryScheduleMilliseconds[index]);
Thread.Sleep(retryScheduleMilliseconds[index]);
HttpRequestMessage retryRequest = BuildRequest(
method,
path,
Expand Down Expand Up @@ -131,7 +138,7 @@ HttpRequestMessage BuildRequest(
object? content = null
)
{
var url = _options.BaseUrl;
var url = serverUrl;

// Apply path parameters if provided
if (pathParams != null)
Expand Down
18 changes: 14 additions & 4 deletions csharp/Svix/SvixOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,26 @@ namespace Svix
{
public class SvixOptions
{
public string BaseUrl { get; }
[Obsolete("BaseUrl is deprecated, please use ServerUrl instead.")]
public string? BaseUrl
{
get => ServerUrl;
}
public string? ServerUrl { get; }
public List<int> RetryScheduleMilliseconds { get; } = [50, 100, 200];
public int TimeoutMilliseconds { get; } = 15000;

/// <param name="serverUrl">The server URL to connect to.</param>
/// <param name="baseUrl">[Deprecated] Please use serverUrl parameter instead.</param>
#pragma warning disable CS0618
public SvixOptions(
string baseUrl,
string? serverUrl = null,
int timeoutMilliseconds = 15000,
List<int>? retryScheduleMilliseconds = null
List<int>? retryScheduleMilliseconds = null,
string? baseUrl = null
)
{
BaseUrl = baseUrl;
ServerUrl = serverUrl ?? baseUrl;
TimeoutMilliseconds = timeoutMilliseconds;
retryScheduleMilliseconds ??= [50, 100, 200];
if (retryScheduleMilliseconds.Count > 5)
Expand All @@ -21,5 +30,6 @@ public SvixOptions(
}
RetryScheduleMilliseconds = retryScheduleMilliseconds;
}
#pragma warning restore CS0618
}
}
4 changes: 3 additions & 1 deletion csharp/Svix/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ internal static string DefaultServerUrlFromToken(string token)
}
else
{
return "https://api.svix.com";
return DEFAULT_SERVER_URL;
}
}

internal static string DEFAULT_SERVER_URL = "https://api.svix.com";
}
}