{"id":18536335,"url":"https://github.com/bakerjq/rxretrohttp","last_synced_at":"2025-07-17T12:41:24.926Z","repository":{"id":92171865,"uuid":"165846074","full_name":"BakerJQ/RxRetroHttp","owner":"BakerJQ","description":"RxJava2 + Retrofit2 http request lib,  supports multiple api result data structures and multiple urls. Http请求库，支持同时存在多种返回格式和多个base url","archived":false,"fork":false,"pushed_at":"2024-01-05T11:17:38.000Z","size":230,"stargazers_count":57,"open_issues_count":1,"forks_count":10,"subscribers_count":5,"default_branch":"master","last_synced_at":"2024-01-06T07:41:30.345Z","etag":null,"topics":["http","retrofit","retrofit2","rxjava","rxjava2"],"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/BakerJQ.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}},"created_at":"2019-01-15T12:20:03.000Z","updated_at":"2024-01-06T07:41:30.346Z","dependencies_parsed_at":"2024-01-05T07:39:50.664Z","dependency_job_id":"ada84376-897b-4aeb-b87c-6ba63881f7a5","html_url":"https://github.com/BakerJQ/RxRetroHttp","commit_stats":null,"previous_names":[],"tags_count":19,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BakerJQ%2FRxRetroHttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BakerJQ%2FRxRetroHttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BakerJQ%2FRxRetroHttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BakerJQ%2FRxRetroHttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BakerJQ","download_url":"https://codeload.github.com/BakerJQ/RxRetroHttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223403391,"owners_count":17139891,"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":["http","retrofit","retrofit2","rxjava","rxjava2"],"created_at":"2024-11-06T19:32:26.434Z","updated_at":"2025-07-17T12:41:24.919Z","avatar_url":"https://github.com/BakerJQ.png","language":"Java","readme":"# RxRetroHttp\n[![License](https://img.shields.io/badge/license-Apache%202-4EB1BA.svg)](https://www.apache.org/licenses/LICENSE-2.0.html)\n[![](https://jitpack.io/v/BakerJQ/RxRetroHttp.svg)](https://jitpack.io/#BakerJQ/RxRetroHttp)\n\nAndroid http request lib,  supports multiple api result data structures and multiple urls\n\nHttp请求库，支持同时存在多种返回格式和多个base url（[中文文档](https://github.com/BakerJQ/RxRetroHttp/blob/master/README_cn.md)）\n## Why RxRetroHttp\nIn some case, we have to include more than one http request style -- eg. multiple result structure, multiple host address, multiple http settings, etc-- in one app.\n\nThis usually happens when we need to use some third party api or combine multiple system in one project.\n\nRxRetroHttp suppose to simplify your http request realization in this situation.\n\n## Gradle via JitPack\nAdd it in your root build.gradle at the end of repositories:\n``` groovy\nallprojects {\n    repositories {\n        ...\n        maven { url 'https://jitpack.io' }\n    }\n}\n```\nAdd the dependency\n``` groovy\ndependencies {\n    implementation 'com.github.BakerJQ:RxRetroHttp:1.2.10'\n}\n\n```\n\n## How to use\n### Initialize\n#### Main Api Request\nInitialize the sdk in Application, the code below shows the initialization of the main url request settings\n```java\nRxRetroHttp.init(this)\n           .setBaseUrl(\"https://api.github.com/\")//your main url\n           .setDefaultErrMsg(\"Github开小差了\")//default error hint message\n           .setApiResultClass(GithubApiResult.class)//your main api result structure, if not, will use default gson converter\n           .generateRetroClient()\n```\n#### Other Api Request\nIf your app includes other api request, try the code below\n\nMention:\n- You need to do this after you called init()\n- DON'T forget to add the 'Tag' in generateRetroClient() function\n- If you don't set an ApiResultClass, the lib will use GsonConverterFactory as default, this means that the lib will not deal with response logic for you, or you can add your own ResponseConverter\n\n```java\nRxRetroHttp.getInstance()\n           .setApiResultClass(YourApiResult.class)//other result\n           .setBaseUrl(\"http://host/api/data/\")//other url\n           .generateRetroClient(\"YourTag\");//other request tag\n```\n\n#### Settings\nYou can customize your http settings by get and reset the builders, or calling setting functions\n\nMention: This must be done AFTER init() and BEFORE generateRetroClient() function\n\n```java\nRxRetroHttp.init().setXXX().setXXX();\nRetrofit.Builder retrofitBuilder = RxRetroHttp.getRetrofitBuilder();\nretrofitBuilder.setXXX().setXXX();\nOkHttpClient.Builder okHttpBuilder = RxRetroHttp.getOkHttpClientBuilder();\nokHttpBuilder.setXXX().setXXX();\nRxRetroHttp.getInstance().generateRetroClient();\n//RxRetroHttp.getInstance().generateRetroClient(\"YourTag\")\n```\n\n### Api Request\n#### Step 1. Define Api Result Structure by Implement IApiResult\nCode below is just a simple sample\n```java\npublic class YourApiResult\u003cT\u003e implements IApiResult\u003cT\u003e {\n    private int code;//result code\n    private String msg;//result message\n    private T result;//result data\n    //define what means a successful result(eg. code == 1)\n    @Override\n    public boolean isSuccess();\n    //return the structured data\n    @Override\n    public T getData();\n    //return the message\n    @Override\n    public String getResultMsg();\n    //return the code\n    @Override\n    public String getResultCode();\n    //return the key name of \"result\" in the response json\n    @Override\n    public String getDataField();\n}\n```\n#### Step 2. Define Retrofit Api Service\nDefine the ApiService, to be mentioned, you DO NOT need to use wrapped api result like \"Observable\u003cYourApiResult\u003c TestInfo \u003e\u003e\", and add RetroTag annotation if this is a tagged request\n```java\n@RetroTag(\"YourTag\")\npublic interface YourApiService {\n    @GET(\"test/info\")\n    Observable\u003cTestInfo\u003e getTestInfo();\n    @GET(\"test/list\")\n    Observable\u003cList\u003cTestInfo\u003e\u003e getTestInfo();\n}\n```\n#### Step 3. Call Request\nJust define a call like Retrofit\n```java\nRxRetroHttp.create(YourApiService.class).getTestInfo()\n```\n\n### Mock Data\nYou can mock your api data in two ways: from file or from json string.\n\nYou should enable mock when init;\n\n```java\nRxRetroHttp.init(this).setMockEnable(true)\n```\n\n#### Mock From File\nStep 1. Put your mock data file under assets dir\n\nStep 2. Add headers to your api function\n\n```java\n@Headers({RxRetroHttp.MOCK_FILE_PATH_KEY + \":mockfile.json\")\n@GET(\"test/info\")\nObservable\u003cTestInfo\u003e getTestInfo();\n```\n\n#### Mock From Json String\nJust add headers to your api function\n\n```java\n@Headers({RxRetroHttp.MOCK_DATA_KEY + \":{\\\"testInfo\\\":\\\"info\\\"}\")\n@GET(\"test/info\")\nObservable\u003cTestInfo\u003e getTestInfo();\n```\n\n#### Header Keys\n\n| key | desc |\n| ---- | ---- |\n| MOCK_DATA_KEY | mock json string |\n| MOCK_FILE_PATH_KEY | mock assets file path |\n| MOCK_ENABLE_KEY | enable or disable mock |\n| MOCK_DELAY_KEY | delay duration of response |\n\n## Proguard\n- Add Retrofit proguard\n- Add OkHttp proguard\n- Deal with your data entity\n\n## For Android Api Level 21-\nFor 21- projects, add the dependency like below\n``` groovy\ndependencies {\n    implementation ('com.github.BakerJQ:RxRetroHttp:1.2.0'){\n        exclude group: 'com.squareup.okhttp3', module: 'okhttp'\n    }\n    implementation 'com.squareup.okhttp3:okhttp:3.12.0'\n}\n```\n\n## Thanks\nThanks To （[RxEasyHttp](https://github.com/zhou-you/RxEasyHttp)）\n\n## *License*\nRxRetroHttp is released under the Apache 2.0 license.\n\n```\nCopyright 2019 BakerJ.\n\nLicensed under the Apache License, Version 2.0 (the \"License\");\nyou may not use this file except in compliance with the License.\nYou may obtain a copy of the License at following link.\n\n     http://www.apache.org/licenses/LICENSE-2.0\n\nUnless required by applicable law or agreed to in writing, software\ndistributed under the License is distributed on an \"AS IS\" BASIS,\nWITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\nSee the License for the specific language governing permissions and\nlimitations under the License.\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakerjq%2Frxretrohttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbakerjq%2Frxretrohttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbakerjq%2Frxretrohttp/lists"}