Skip to content

Commit 86e0e2a

Browse files
feat(flags): switch local evaluation endpoint to /flags/definitions (#173)
* feat(flags): switch local evaluation endpoint to /flags/definitions * refactor(tests): deduplicate LocalEvaluationUrl into single internal constant
1 parent 41620d3 commit 86e0e2a

6 files changed

Lines changed: 10 additions & 11 deletions

File tree

src/PostHog/Api/LocalEvaluationApiResult.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
namespace PostHog.Api;
66

77
/// <summary>
8-
/// The API Payload from the <c>/api/feature_flag/local_evaluation</c> endpoint used to evaluate feature flags
8+
/// The API Payload from the <c>/flags/definitions</c> endpoint used to evaluate feature flags
99
/// locally.
1010
/// </summary>
1111
internal record LocalEvaluationApiResult

src/PostHog/Api/PostHogApiClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ public async Task<ApiResult> SendEventAsync(
144144

145145
/// <summary>
146146
/// Retrieves all the feature flags for the project by making a request to the
147-
/// <c>/api/feature_flag/local_evaluation</c> endpoint. This requires that a Personal API Key is set in
147+
/// <c>/flags/definitions</c> endpoint. This requires that a Personal API Key is set in
148148
/// <see cref="PostHogOptions"/>.
149149
/// </summary>
150150
/// <param name="etag">Optional ETag from a previous request for conditional fetching.</param>
@@ -155,7 +155,7 @@ public async Task<LocalEvaluationResponse> GetFeatureFlagsForLocalEvaluationAsyn
155155
string? etag,
156156
CancellationToken cancellationToken)
157157
{
158-
var uriBuilder = new UriBuilder(new Uri(HostUrl, "/api/feature_flag/local_evaluation"))
158+
var uriBuilder = new UriBuilder(new Uri(HostUrl, "/flags/definitions"))
159159
{
160160
Query = $"token={Uri.EscapeDataString(ProjectApiKey)}&send_cohorts"
161161
};

tests/TestLibrary/Fakes/FakeHttpMessageHandlerExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public static void AddRepeatedFlagsResponse(this FakeHttpMessageHandler handler,
6868
public static void AddRepeatedFlagsResponse(this FakeHttpMessageHandler handler, int count, string responseBody)
6969
=> handler.AddRepeatedFlagsResponse(count, _ => responseBody);
7070

71-
static readonly Uri LocalEvaluationUrl = new("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts");
71+
internal static readonly Uri LocalEvaluationUrl = new("https://us.i.posthog.com/flags/definitions?token=fake-project-api-key&send_cohorts");
7272

7373
public static FakeHttpMessageHandler.RequestHandler AddLocalEvaluationResponse(
7474
this FakeHttpMessageHandler handler,

tests/UnitTests/Features/FeatureFlagsTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3354,7 +3354,7 @@ public async Task ReturnsEmptyDictionaryWhenPersonalApiKeyIncorrect()
33543354
FeatureFlagPayloads = new Dictionary<string, string>(),
33553355
});
33563356
container.FakeHttpMessageHandler.AddResponse(
3357-
new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"),
3357+
FakeHttpMessageHandlerExtensions.LocalEvaluationUrl,
33583358
HttpMethod.Get,
33593359
new HttpResponseMessage(HttpStatusCode.Unauthorized)
33603360
{
@@ -3510,7 +3510,7 @@ public async Task ReturnsEmptyDictionaryWhenLocalEvaluationQuotaExceeded()
35103510
// When local evaluation is quota limited, we do not want to fallback to /decide.
35113511
var decideHandler = container.FakeHttpMessageHandler.AddFlagsResponseException(new InvalidOperationException());
35123512
container.FakeHttpMessageHandler.AddResponse(
3513-
new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"),
3513+
FakeHttpMessageHandlerExtensions.LocalEvaluationUrl,
35143514
HttpMethod.Get,
35153515
new HttpResponseMessage(HttpStatusCode.PaymentRequired)
35163516
{
@@ -3542,7 +3542,7 @@ public async Task ReturnsFalseWhenSingleFlagLocalEvaluationRequestQuotaExceeded(
35423542
var container = new TestContainer("fake-personal-api-key");
35433543
var decideHandler = container.FakeHttpMessageHandler.AddFlagsResponseException(new InvalidOperationException());
35443544
container.FakeHttpMessageHandler.AddResponse(
3545-
new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts"),
3545+
FakeHttpMessageHandlerExtensions.LocalEvaluationUrl,
35463546
HttpMethod.Get,
35473547
new HttpResponseMessage(HttpStatusCode.PaymentRequired)
35483548
{

tests/UnitTests/Features/LocalFeatureFlagsLoaderTests.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,7 @@ public class TheDisposeAsyncMethod
2929
}
3030
""";
3131

32-
static readonly Uri LocalEvaluationUrl =
33-
new("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts");
32+
static readonly Uri LocalEvaluationUrl = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl;
3433

3534
[Fact]
3635
public async Task CompletesGracefullyDuringInFlightPoll()

tests/UnitTests/PostHogClientTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1510,7 +1510,7 @@ public async Task RespectsCancellationToken()
15101510
{
15111511
var container = new TestContainer(personalApiKey: "fake-personal-api-key");
15121512
// Add a handler that will throw OperationCanceledException
1513-
var uri = new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts");
1513+
var uri = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl;
15141514
container.FakeHttpMessageHandler.AddResponseException(uri, HttpMethod.Get, new OperationCanceledException());
15151515
var client = container.Activate<PostHogClient>();
15161516

@@ -1529,7 +1529,7 @@ public async Task DoesNotLogErrorForCancellation()
15291529
{
15301530
var container = new TestContainer(personalApiKey: "fake-personal-api-key");
15311531
// Add a handler that will throw OperationCanceledException
1532-
var uri = new Uri("https://us.i.posthog.com/api/feature_flag/local_evaluation?token=fake-project-api-key&send_cohorts");
1532+
var uri = FakeHttpMessageHandlerExtensions.LocalEvaluationUrl;
15331533
container.FakeHttpMessageHandler.AddResponseException(uri, HttpMethod.Get, new OperationCanceledException());
15341534
var client = container.Activate<PostHogClient>();
15351535

0 commit comments

Comments
 (0)