{"id":50878324,"url":"https://github.com/FabianTerhorst/ApiClient","last_synced_at":"2026-07-03T02:01:10.385Z","repository":{"id":73384264,"uuid":"50875880","full_name":"FabianTerhorst/ApiClient","owner":"FabianTerhorst","description":"A easy to use api client that combines the power of Retrofit, Realm, Gson, Rxjava and Retrolambda in a easy to use library for Java and Android","archived":false,"fork":false,"pushed_at":"2017-06-09T12:35:24.000Z","size":136,"stargazers_count":96,"open_issues_count":4,"forks_count":16,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-12T18:27:57.836Z","etag":null,"topics":["activity-lifecycle","apiclient","gson","realm","rxjava"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/FabianTerhorst.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","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":"2016-02-01T22:23:36.000Z","updated_at":"2024-08-12T19:21:13.000Z","dependencies_parsed_at":null,"dependency_job_id":"31fa78ff-cd68-4e54-a06d-6d2d38e70a77","html_url":"https://github.com/FabianTerhorst/ApiClient","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"purl":"pkg:github/FabianTerhorst/ApiClient","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabianTerhorst%2FApiClient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabianTerhorst%2FApiClient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabianTerhorst%2FApiClient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabianTerhorst%2FApiClient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/FabianTerhorst","download_url":"https://codeload.github.com/FabianTerhorst/ApiClient/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/FabianTerhorst%2FApiClient/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35069183,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-05-26T15:22:16.424Z","status":"online","status_checked_at":"2026-07-03T02:00:05.635Z","response_time":110,"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":["activity-lifecycle","apiclient","gson","realm","rxjava"],"created_at":"2026-06-15T12:00:25.784Z","updated_at":"2026-07-03T02:01:10.376Z","avatar_url":"https://github.com/FabianTerhorst.png","language":"Java","funding_links":[],"categories":["HTTP客户端"],"sub_categories":["微服务框架"],"readme":"# ApiClient\nA easy to use api client that combines the power of Retrofit, Realm, Gson, Rxjava and Retrolambda in a library for Java and Android\n\n##### Add to build.gradle\n\n```groovy\ncompile 'io.fabianterhorst:apiclient:0.4'\ncompile 'io.fabianterhorst:apiclient-accountmanager:0.1'\ncompile 'io.fabianterhorst:apiclient-components:0.1'\n```\n\n#### First Step\n\nCreate your Api Class\n\n```java\npublic class Twitter extends ApiClient\u003cTwitterApi\u003e implements TwitterApi {\n\n    public Twitter(Realm realm, String apiKey) {\n        super(realm, TwitterApi.PARAM_API_KEY, apiKey, TwitterApi.class, TwitterApi.END_POINT);\n    }\n\n    public static void init(String apiKey) {\n        init(new Twitter(apiKey));\n    }\n\n    @Override\n    public Observable\u003cList\u003cCharacter\u003e\u003e getTweets() {\n    \t//Here you can define the tablename for realm and the fieldname if needed to sort the tweets with\n        return getApiObservable(getApi().getTweets(), Tweet.class, \"name\");\n    }\n\n    @Override\n    public Observable\u003cList\u003cCharacter\u003e\u003e getComments(ArrayList\u003cInteger\u003e ids) {\n    \t//You can also get results only for specific ids\n        return getApiObservable(getApi().getComments(), Comment.class, \"id\", ids);\n    }\n}\n```\n\n#### Second Step\n\nCreate your Api Interface (The Retrofit way)\n\n```java\npublic interface TwitterApi {\n\t\n\t@GET(\"tweets\")\n\tObservable\u003cList\u003cTweet\u003e\u003e getTweets();\n\n\t@GET(\"comments\")\n\tObservable\u003cList\u003cTweet\u003e\u003e getComments(@Query(\"id\") ArrayList\u003cInteger\u003e ids);\n}\n```\n\n#### Third Step\n\nInitiate the Singleton in the Application onCreate\n\n```java\npublic class MyApplication extends Application {\n\n    @Override\n    public void onCreate() {\n        super.onCreate();\n        RealmConfiguration config = new RealmConfiguration.Builder(this)\n                .deleteRealmIfMigrationNeeded()\n                .build();\n        Realm.setDefaultConfiguration(config);\n        Twitter.init(\"0123456789\");\n    }\n}\n```\n\n#### Fourth Step\n\nUse it and have fun. The library is handling the saving, the loading and the refreshing for you.\n\n```java\nTwitter twitter = Twitter.getInstance();\n\ntwitter.getTweets().subscribe(tweets-\u003e System.out.println(tweets));\n```\n\n### FAQ\n\n##### How to handle Android Activity lifecycle\n\nYou can use the ApiClient component module to get access to RxActivity and RxFragment\n\nIn your Activity you have to get the Singleton with the Activity lifecycle. Your activity has to extend RxActivity.\n\n```java\nTwitter twitter = Twitter.getInstance(bindToLifecycle());\n```\n\nAnd thats everythink you have to do to prevent memory leaks.\n\n##### RealmList doesn´t support null objects. How can i ignore null object inside the response json?\n\nYou can override the gson builder inside your api class and add custom deserializer adapters to avoid adding null objects.\n\n```java\n@Override\npublic GsonBuilder getGsonBuilder(GsonBuilder gsonBuilder) {\n    GsonUtils.registerRemoveNullListSerializer(gsonBuilder, new TypeToken\u003cRealmList\u003cMyFirstObject\u003e\u003e() {}, MyFirstObject.class);\n    GsonUtils.registerRemoveNullListSerializer(gsonBuilder, new TypeToken\u003cRealmList\u003cMySecondObject\u003e\u003e() {}, MySecondObject.class);\n    GsonUtils.registerRemoveNullListSerializer(gsonBuilder, new TypeToken\u003cRealmList\u003cMyThirdObject\u003e\u003e() {}, MyThirdObject.class);\n    return gsonBuilder;\n}\n```\n\n##### How to change the api key from everywhere?\n\nYou can use the ```setApiKey``` method.\n\n```java\nTwitter.getInstance().setApiKey(\"9876543210\");\n```\n\n##### How to add other query parameters?\n\nYou can override the ```getHttpUrlBuilder(HttpUrl.Builder builder)``` method from the api client.\n\n```java\n@Override\npublic HttpUrl.Builder getHttpUrlBuilder(HttpUrl.Builder builder) {\n    return addQueryParameter(\"lang\", Locale.getDefault().getLanguage());\n}\n```\n\n##### How to use a authentication\n\nThe easiest way is to use the AuthUtils to add a authentication via the request builder for post parameters and headers or the http url builder for query parameter\n\nmyurl.com/api\n```java\n@Override\npublic Request.Builder getRequestBuilder(Request.Builder builder) {\n    return AuthUtils.addDefaultAuthentication(builder, getApiKey());\n}\n```\n\nmyurl.com/api?apiKey=012345\n```java\n@Override\npublic HttpUrl.Builder getHttpUrlBuilder(HttpUrl.Builder builder) {\n    AuthUtils.addDefaultAuthentication(builder, \"apiKey\", getApiKey());\n        return builder.addQueryParameter(\"lang\", Locale.getDefault().getLanguage());\n}\n```\n\n### License\n    Copyright 2016 Fabian Terhorst\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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabianTerhorst%2FApiClient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FFabianTerhorst%2FApiClient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FFabianTerhorst%2FApiClient/lists"}