{"id":27966503,"url":"https://github.com/techery/janet-proxy","last_synced_at":"2025-10-14T16:05:49.313Z","repository":{"id":75020310,"uuid":"83353806","full_name":"techery/janet-proxy","owner":"techery","description":"ActionService for Janet which delegates actions to another services","archived":false,"fork":false,"pushed_at":"2017-03-21T11:13:55.000Z","size":69,"stargazers_count":1,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-10-14T16:04:27.097Z","etag":null,"topics":[],"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/techery.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":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2017-02-27T20:31:44.000Z","updated_at":"2019-06-25T08:22:52.000Z","dependencies_parsed_at":null,"dependency_job_id":"d38c9c1a-2179-44b0-a599-3ca2eb63e205","html_url":"https://github.com/techery/janet-proxy","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/techery/janet-proxy","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fjanet-proxy","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fjanet-proxy/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fjanet-proxy/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fjanet-proxy/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/techery","download_url":"https://codeload.github.com/techery/janet-proxy/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/techery%2Fjanet-proxy/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279019554,"owners_count":26086750,"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","status":"online","status_checked_at":"2025-10-14T02:00:06.444Z","response_time":60,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-05-07T20:19:10.435Z","updated_at":"2025-10-14T16:05:49.307Z","avatar_url":"https://github.com/techery.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"## ProxyService\nActionService for [Janet](https://github.com/techery/janet) which delegates actions to another services.  \n\n### Getting Started\n\n#### 1. Define some contract for services' actions\nContract could be anything: from marker interface to logical expression by class name - it's totally up to you.\n\nE.g. let's use interface with String identifier:\n```java\npublic interface LabeledAction {\n  String label();\n}\n```\n\n```java\n@SomeServiceAction\npublic class SomeServiceAction1 implements LabeledAction {\n  @Override public String label() {\n    return \"service1\";\n  }\n}\n```\n\n```java\n@SomeServiceAction\npublic class SomeServiceAction2 implements LabeledAction {\n  @Override public String label() {\n    return \"service2\";\n  }\n}\n```\n\n#### 2. Define service and add it to `Janet`\n```java\nSomeService service1 = new SomeService();\nSomeService service2 = new SomeService();\n//\n// service1 and service2 must process actions of same annotation type as specified for ProxyService\n//\nActionService proxyService = new ProxyService.Builder(SomeServiceAction.class)\n        .add(service1, new ServiceMappingRule\u003cLabeledAction\u003e() {\n          @Override public boolean matches(LabeledAction action) {\n            return action.label().equals(\"service1\");\n          }\n        })\n        .add(service2, new ServiceMappingRule\u003cLabeledAction\u003e() {\n          @Override public boolean matches(LabeledAction action) {\n            return action.label().equals(\"service2\");\n          }\n        })\n        .build();\n//\nJanet janet = new Janet.Builder().addService(proxyService).build();\n```\n\n#### 3. Use `ActionPipe` to send/observe action as usual\n```java\nActionPipe\u003cSomeServiceAction1\u003e actionPipe = janet.createPipe(SomeServiceAction1.class);\nactionPipe\n  .createObservable(new SomeServiceAction1())\n  .subscribeOn(Schedulers.io())\n  .subscribe(new ActionStateSubscriber\u003cSomeServiceAction1\u003e()\n          .onSuccess(action -\u003e System.out.println(\"SomeServiceAction1 has been executed on SomeService with label 'service1'\"))\n  );\n```\n\n### Real use-case\nPrecondition: you have several http endpoints and want to use the only 1 instance of `Janet`\n```java\nOkClient client = new OkClient();\nGsonConverter converter = new GsonConverter(new Gson());\n\nJanet janet = new Janet.Builder()\n    .addService(new SampleLoggingService(new ProxyService.Builder(HttpAction.class)\n        .add(\n            new HttpActionService(\"https://api.github.com\", client, converter),\n            (LabeledAction action) -\u003e action.label().equals(\"github\"))\n        .add(\n            new HttpActionService(\"http://xkcd.com\", client, converter),\n            (LabeledAction action) -\u003e action.label().equals(\"xkcd\"))\n        .build()\n    )).build();\n\nObservable.combineLatest(\n    janet.createPipe(GithubAction.class, Schedulers.io()).createObservableResult(new GithubAction()),\n    janet.createPipe(XkcdAction.class, Schedulers.io()).createObservableResult(new XkcdAction()),\n    (githubAction, xkcdAction) -\u003e null\n).toBlocking().subscribe();\n```\n\n```java\n@HttpAction(\"/info.0.json\")\npublic class XkcdAction implements LabeledAction {\n\n  @Override public String getLabel() {\n    return \"xkcd\";\n  }\n\n  @Response XkcdData data;\n}\n```\n\n```java\n@HttpAction(\"/users/techery/repos\")\npublic class GithubAction implements LabeledAction {\n\n  @Override public String getLabel() {\n    return \"github\";\n  }\n\n  @Response ArrayList\u003cRepository\u003e repositories;\n}\n```\n\nThe output:\n```\nsend XkcdAction{data=null}\nsend GithubAction{repositories=null}\nonStart GithubAction{repositories=null}\nonStart XkcdAction{data=null}\nonSuccess XkcdAction{data=XkcdData{img='https://imgs.xkcd.com/comics/video_content.png', title='Video Content'}}\nonSuccess GithubAction{repositories=[Repository{name='ABFRealmMapView', description='Real-time map view clustering for Realm'}, ... , Repository{name='Doppelganger', description='Array diffs as collection view wants it'}]}\n```\n\n### Download\n```groovy\nrepositories {\n    jcenter()\n    maven { url \"https://jitpack.io\" }\n}\n\ndependencies {\n    compile 'com.github.techery:janet-proxy:xxx'\n    // explicitly depend on latest Janet for bug fixes and new features (optionally)\n    compile 'com.github.techery:janet:zzz' \n}\n```\n* janet: [![](https://jitpack.io/v/techery/janet.svg)](https://jitpack.io/#techery/janet)\n* janet-proxy: [![](https://jitpack.io/v/techery/janet-proxy.svg)](https://jitpack.io/#techery/janet-proxy)\n[![Build Status](https://travis-ci.org/techery/janet-proxy.svg?branch=master)](https://travis-ci.org/techery/janet-proxy)\n\n## License\n\n    Copyright (c) 2017 Techery\n\n    Licensed under the Apache License, Version 2.0 (the \"License\");\n    you may not use this file except in compliance with the License.\n    You may obtain a copy of the License at\n\n       http://www.apache.org/licenses/LICENSE-2.0\n\n    Unless required by applicable law or agreed to in writing, software\n    distributed under the License is distributed on an \"AS IS\" BASIS,\n    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n    See the License for the specific language governing permissions and\n    limitations under the License.\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechery%2Fjanet-proxy","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftechery%2Fjanet-proxy","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftechery%2Fjanet-proxy/lists"}