Skip to content
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

feat: Add get_applicable_variants as expt endpoint #210

Merged
merged 1 commit into from
Sep 16, 2024

Conversation

ayushjain17
Copy link
Collaborator

@ayushjain17 ayushjain17 commented Aug 23, 2024

Problem

get_applicable_variants only exist as a functionality inside client

Solution

Add get_applicable_variants as an endpoint in experimentation

API changes

Endpoint Method Request body Response Body
/experiments/applicable_variants POST {context: Value, toss: i8} Vec<Variants>

Possible Issues in the future

Code duplication

Ok(HttpResponse::Ok().json(variants))
}

fn decide_variant(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

move to helper.rs

if is_empty {
Some(exp.clone())
} else {
match jsonlogic::partial_apply(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why partial apply ?

}
}

impl FromRequest for ApplicableVariantsQuery {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally we should not use fromrequest for individual types , as actix_web already has fromrequest implementation
for all http request data type

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use try_from in the handler , and expect query param as HashMap<String,String>

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

doing it manually, it becomes quite flaky and something which is like the dev has to separately ensure the safety of the type and not the system

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But then everyone will add from_request impl for all the types

None
}
})
.ok_or_else(|| {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

shouldn't toss be optional and default should be -1 ?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

get_applicable_variant is based on toss itself, toss is mandatory here

@ayushjain17 ayushjain17 force-pushed the applicableVariants branch 2 times, most recently from 59afb0a to 8ff9c81 Compare September 16, 2024 13:31
@ayushjain17 ayushjain17 merged commit 54f2037 into main Sep 16, 2024
4 checks passed
@ayushjain17 ayushjain17 deleted the applicableVariants branch September 16, 2024 16:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants