{"id":20994071,"url":"https://github.com/tradeshift/flagr-java","last_synced_at":"2025-06-21T07:34:57.841Z","repository":{"id":39890555,"uuid":"247068592","full_name":"Tradeshift/flagr-java","owner":"Tradeshift","description":"Java Client for Flagr","archived":false,"fork":false,"pushed_at":"2025-04-25T14:53:23.000Z","size":115,"stargazers_count":3,"open_issues_count":5,"forks_count":14,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-04-25T15:45:20.551Z","etag":null,"topics":["developer-productivity"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Tradeshift.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-03-13T12:41:07.000Z","updated_at":"2025-02-03T08:12:10.000Z","dependencies_parsed_at":"2024-01-17T08:22:43.665Z","dependency_job_id":"de7bf209-b6a3-49b4-b5b9-cf9042da2e9c","html_url":"https://github.com/Tradeshift/flagr-java","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fflagr-java","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fflagr-java/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fflagr-java/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Tradeshift%2Fflagr-java/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Tradeshift","download_url":"https://codeload.github.com/Tradeshift/flagr-java/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254230746,"owners_count":22036230,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["developer-productivity"],"created_at":"2024-11-19T07:16:46.391Z","updated_at":"2025-05-14T21:30:37.072Z","avatar_url":"https://github.com/Tradeshift.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flagr Java\n\nAn easy to use client for the [Flagr](https://checkr.github.io/flagr) feature flag service.\n\n## General Concepts used in this documentation\n * **Flag** can be a feature flag or an experiment.\n * **Context** is the information that needs to be provided to evaluate a **flag**.\n * **Variant** represents the possible variation of a flag.\n * **Variant Attachment**  is additional meta information that you can return with your **variant**.\n\nFor more in depth information visit [Flagr official docs](https://checkr.github.io/flagr/#/home).\n\n## Installation\n\nAdd the following dependency to `pom.xml`:\n```xml\n\u003cdependencies\u003e\n    \u003cdependency\u003e\n        \u003cgroupId\u003ecom.tradeshift\u003c/groupId\u003e\n        \u003cartifactId\u003eflagr-java\u003c/artifactId\u003e\n        \u003cversion\u003e0.9.4\u003c/version\u003e\n    \u003c/dependency\u003e\n\u003c/dependencies\u003e\n```\n\n## Usage\n\nAssume there's a flag called `color` for changing the blue background color of a page for a red one for 10% of the clients. Here is what the code for evaluating this flag would look like:\n\n````java\nflagr = new Flagr(FLAGR_HOST);\ntry {\n    EvaluationResponse response = flagr.evaluate(\n        new EvaluationContext(\"background_color\")\n    );\n    System.out.println(response.getVariantKey()); // The variant will be red for 10% of evaluations\n} catch (FlagrException e) {\n    e.printStackTrace();\n}\n````\n\nIf one of the clients is testing the red background and only this client is supposed to see the red background?\nThe code above can send the client properties to Flagr so it knows about the client. Then on Flagr Admin UI you can specify that only your test client will see the red background.\nThe code for this example would look like:\n````java\nflagr = new Flagr(FLAGR_HOST);\ntry {\n    EvaluationContext context = new EvaluationContext(\"background_color\");\n    context.setEntityContext(client); // Sends client info to Flagr so you can filter by one of it's properties on the UI.\n    EvaluationResponse response = flagr.evaluate(context);\n    System.out.println(response.getVariantKey()); // This would return red for the client(s) you select on Flagr UI.\n} catch (FlagrException e) {\n    e.printStackTrace();\n}\n````\n\nIf the variant needs properties as well, this can be achieved by creating\na variant attachment and describing it's properties on Flagr UI. Suppose\ncolor has the properties name and hexadecimal, the code would look like:\n````java\nflagr = new Flagr(FLAGR_HOST);\nClient client = new Client(\"Søren\", \"Tradeshift\");\ntry {\n    EvaluationContext context = new EvaluationContext(\"background_color\");\n    context.setEntityContext(client); // Sends client info to Flagr so you can filter by one of it's properties on the UI.\n    EvaluationResponse response = flagr.evaluate(context);\n    Color color = response.getVariantAttachment(Color.class);\n    System.out.println(response.getVariantKey(color.getName())); // This would return red for the client(s) you select on Flagr UI.\n    System.out.println(response.getVariantKey(color.getHex())); // This would return #FF0000 for example.\n} catch (FlagrException e) {\n    e.printStackTrace();\n}\n````\n\nIf the values from `EvaluationResponse` class doesn't matter and only a Color is needed:\n````java\nflagr = new Flagr(FLAGR_HOST);\nOptional\u003cColor\u003e color = flagr.evaluateVariantAttachment(\n        new EvaluationContext(\"color\"),\n        Color.class,\n);\nif (color.isPresent()){\n    System.out.println(color.get().getName()); //do something with the color\n}\n````\n\nWhen only the variant matters, use:\n````java\nflagr = new Flagr(FLAGR_HOST);\nOptional\u003cString\u003e variantKey = flagr.evaluateVariantKey(new EvaluationContext(\"myflag\")));\n````\n\nAnd if it's just a simple on/off flag. Use the `evaluateBoolean` method. \nIt returns true if the variant evaluates to \"true\", \"enabled\" or \"on\" otherwise it returns false.:\n````java\nflagr = new Flagr(FLAGR_HOST);\nif (flagr.evaluateEnabled(new EvaluationContext(\"onOffFlag\"))) {\n    System.out.println(\"Enabled!\"); // or whatever needs to be done.\n}\n````\n\n## Versioning\n\nWe use [SemVer](http://semver.org/) for versioning.\n\n## Releasing\n\nThis project is released directly to maven central.\n\nAs a Tradeshift employee you must do the following\n\n1. Get access to maven central by [issuing a ticket](https://central.sonatype.org/publish/publish-guide/#create-a-ticket-with-sonatype) on the [sonatype jira project](https://issues.sonatype.org/)\n2. Run `mvn deploy` from your local machine, which include signing the package with your GPG key\n3. Promote the build via their [process for releasing to central](https://central.sonatype.org/publish/publish-guide/#releasing-to-central)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradeshift%2Fflagr-java","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftradeshift%2Fflagr-java","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftradeshift%2Fflagr-java/lists"}