{"id":13617985,"url":"https://github.com/liujingxing/rxhttp","last_synced_at":"2025-04-14T10:30:48.852Z","repository":{"id":37416845,"uuid":"167158553","full_name":"liujingxing/rxhttp","owner":"liujingxing","description":" 🔥🔥🔥 Based on OkHttp encapsulation, support Kotlin Coroutines、RxJava2、RxJava3; 30s to get started.","archived":false,"fork":false,"pushed_at":"2025-02-27T11:56:03.000Z","size":21169,"stargazers_count":3775,"open_issues_count":9,"forks_count":460,"subscribers_count":59,"default_branch":"master","last_synced_at":"2025-02-27T16:22:21.488Z","etag":null,"topics":["andriod","kotlin-coroutines","okhttp-rxhttp","okhttp3","retrofit2","rxhttp","rxjava2","rxjava3"],"latest_commit_sha":null,"homepage":"https://juejin.im/post/5ded221a518825125d14a1d4","language":"Kotlin","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/liujingxing.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":null,"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"lfx_crowdfunding":null,"custom":"https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fa6d3941c2c944e59831640fa0ece60d~tplv-k3u1fbpfcp-watermark.image"}},"created_at":"2019-01-23T09:48:12.000Z","updated_at":"2025-02-27T11:56:07.000Z","dependencies_parsed_at":"2023-01-21T12:00:08.797Z","dependency_job_id":"b78340f4-8e18-4b1a-9c55-b21e6f7cfcf1","html_url":"https://github.com/liujingxing/rxhttp","commit_stats":null,"previous_names":[],"tags_count":101,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liujingxing%2Frxhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liujingxing%2Frxhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liujingxing%2Frxhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/liujingxing%2Frxhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/liujingxing","download_url":"https://codeload.github.com/liujingxing/rxhttp/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248862563,"owners_count":21173830,"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":["andriod","kotlin-coroutines","okhttp-rxhttp","okhttp3","retrofit2","rxhttp","rxjava2","rxjava3"],"created_at":"2024-08-01T20:01:52.174Z","updated_at":"2025-04-14T10:30:48.845Z","avatar_url":"https://github.com/liujingxing.png","language":"Kotlin","readme":"# RxHttp\n\nEnglish | [中文文档](https://github.com/liujingxing/rxhttp/blob/master/README_zh.md)\n\n[![](https://jitpack.io/v/liujingxing/rxhttp.svg)](https://jitpack.io/#liujingxing/rxhttp)\n\n# [(RxHttp 3.0 更新指南，升级必看)](https://github.com/liujingxing/rxhttp/wiki/RxHttp-3.0-%E6%9B%B4%E6%96%B0%E6%8C%87%E5%8D%97%EF%BC%8C%E5%8D%87%E7%BA%A7%E5%BF%85%E7%9C%8B)\n\nA type-safe HTTP client for Android. Written based on OkHttp\n\n\n![sequence_chart_en.jpg](https://p6-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/2e25f9c6aa694b57bd43871eff95cecd~tplv-k3u1fbpfcp-watermark.image)\n\n\n\u003ctable\u003e\n  \u003ctr\u003e\n     \u003cth align=\"center\"\u003eAwait\u003c/th\u003e\n     \u003cth align=\"center\"\u003eFlow\u003c/th\u003e\n     \u003cth align=\"center\"\u003eRxJava\u003cbr\u003e(Kotlin)\u003c/th\u003e\n     \u003cth align=\"center\"\u003eRxJava\u003cbr\u003e(Java)\u003c/th\u003e\n  \u003c/tr\u003e\n \n \u003ctr\u003e\n \u003ctd\u003e\n  \n  ```java\n  //await return User\n  //tryAwait return User?\n  val user = RxHttp.get(\"/server/..\")\n      .add(\"key\", \"value\")\n      .toAwait\u003cUser\u003e()\n      .await() \n  \n  //or awaitResult return kotlin.Result\u003cT\u003e\n  RxHttp.get(\"/server/..\")\n      .add(\"key\", \"value\")\n      .toAwait\u003cUser\u003e()  \n      .awaitResult { \n          //Success\n      }.onFailure {  \n          //Failure\n      } \n  ```\n \u003c/td\u003e\n  \n   \u003ctd\u003e\n  \n  ```java\n  RxHttp.get(\"/server/..\")\n      .add(\"key\", \"value\")\n      .toFlow\u003cUser\u003e()  \n      .catch { \n          //Failure\n      }.collect {  \n          //Success\n      }           \n  ```\n \u003c/td\u003e\n    \n   \u003ctd\u003e\n  \n  ```java\n  RxHttp.get(\"/server/..\")\n      .add(\"key\", \"value\")\n      .toObservable\u003cUser\u003e()  \n      .subscribe({ \n          //Success\n      }, {  \n          //Failure\n      })           \n  ```\n \u003c/td\u003e\n    \n   \u003ctd\u003e\n  \n  ```java\n  RxHttp.get(\"/server/..\")\n      .add(\"key\", \"value\")\n      .toObservable(User.class)  \n      .subscribe(user - \u003e { \n          //Success\n      }, throwable -\u003e {  \n          //Failure\n      })           \n  ```\n \u003c/td\u003e\n  \n \u003c/tr\u003e\n \n \u003c/table\u003e\n\n\n\n## 1、Feature\n\n- Support kotlin coroutines, RxJava2, RxJava3\n\n- Support Gson, Xml, ProtoBuf, FastJson and other third-party data parsing tools\n\n- Supports automatic closure of requests in FragmentActivity, Fragment, View, ViewModel, and any class\n\n- Support global encryption and decryption, add common parameters and headers, network cache, all support a request set up separately\n\n## 2、usage\n\n1、Adding dependencies and configurations\n\n### Required\n\n\u003cdetails\u003e\n\u003csummary\u003e1、Add jitpack to your build.gradle\u003c/summary\u003e\n \n```java\nallprojects {\n    repositories {\n        maven { url \"https://jitpack.io\" }\n    }\n}\n```\n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003e2、Java 8 or higher\u003c/summary\u003e\n \n```java\nandroid {\n    compileOptions {\n        sourceCompatibility JavaVersion.VERSION_1_8\n        targetCompatibility JavaVersion.VERSION_1_8\n    }\n}\n```\n\u003c/details\u003e\n\u003cdetails open\u003e\n\u003csummary\u003e3、Add RxHttp dependency\u003c/summary\u003e\n \n```kotlin\nplugins {\n    // kapt/ksp choose one\n    // id 'kotlin-kapt'\n    id 'com.google.devtools.ksp' version '2.0.0-1.0.24'\n}\n    \ndependencies {\n    def rxhttp_version = '3.3.2'\n    implementation 'com.squareup.okhttp3:okhttp:4.12.0'  \n    implementation \"com.github.liujingxing.rxhttp:rxhttp:$rxhttp_version\"\n    // ksp/kapt/annotationProcessor choose one\n    ksp \"com.github.liujingxing.rxhttp:rxhttp-compiler:$rxhttp_version\"\n }\n```\n\u003c/details\u003e\n\n### Optional\n\n### 1、Converter\n```kotlin\nimplementation \"com.github.liujingxing.rxhttp:converter-serialization:$rxhttp_version\"\nimplementation \"com.github.liujingxing.rxhttp:converter-fastjson:$rxhttp_version\"\nimplementation \"com.github.liujingxing.rxhttp:converter-jackson:$rxhttp_version\"\nimplementation \"com.github.liujingxing.rxhttp:converter-moshi:$rxhttp_version\"\nimplementation \"com.github.liujingxing.rxhttp:converter-protobuf:$rxhttp_version\"\nimplementation \"com.github.liujingxing.rxhttp:converter-simplexml:$rxhttp_version\"\n```\n\n### 2、RxJava\n\u003cdetails open\u003e\n\u003csummary\u003eRxHttp + RxJava3\u003c/summary\u003e\n \n ```java\nimplementation 'io.reactivex.rxjava3:rxjava:3.1.6'\nimplementation 'io.reactivex.rxjava3:rxandroid:3.0.2'\nimplementation 'com.github.liujingxing.rxlife:rxlife-rxjava3:2.2.2' //RxJava3, Automatic close request\n```\n \n\u003c/details\u003e\n\u003cdetails\u003e\n\u003csummary\u003eRxHttp + RxJava2\u003c/summary\u003e\n \n```java\nimplementation 'io.reactivex.rxjava2:rxjava:2.2.8'\nimplementation 'io.reactivex.rxjava2:rxandroid:2.1.1'\nimplementation 'com.github.liujingxing.rxlife:rxlife-rxjava2:2.2.2' //RxJava2, Automatic close request\n```\n\u003c/details\u003e\n\n\u003cdetails open\u003e\n\u003csummary\u003eksp passes the RxJava version\u003c/summary\u003e\n \n```java\nksp {\n    arg(\"rxhttp_rxjava\", \"3.1.6\")\n}\n```\n \n\u003c/details\u003e\n\n\u003cdetails\u003e\n\u003csummary\u003eKapt passes the RxJava version\u003c/summary\u003e\n \n```java\nkapt {\n    arguments {\n        arg(\"rxhttp_rxjava\", \"3.1.6\")\n    }\n}\n```\n \n\u003c/details\u003e\n \n\u003cdetails\u003e\n\u003csummary\u003ejavaCompileOptions passes the RxJava version\u003c/summary\u003e\n \n```java\nandroid {\n    defaultConfig {\n        javaCompileOptions {\n            annotationProcessorOptions {\n                arguments = [\n                    rxhttp_rxjava: '3.1.6', \n                ]\n            }\n        }\n    }\n}\n```\n \n\u003c/details\u003e\n\n\n### 3、set RxHttp class package name\n\n\u003cdetails open\u003e\n\u003csummary\u003eksp pass package name\u003c/summary\u003e\n \n```java\nksp {\n     arg(\"rxhttp_package\", \"rxhttp.xxx\")\n}\n```\n    \n\u003cdetails\u003e\n\u003csummary\u003ekapt pass package name\u003c/summary\u003e\n \n```java\nkapt {\n    arguments {\n       arg(\"rxhttp_package\", \"rxhttp.xxx\") \n    }\n}\n```\n \n\u003c/details\u003e\n \n\u003cdetails\u003e\n\u003csummary\u003ejavaCompileOptions pass package name\u003c/summary\u003e\n \n```java\nandroid {\n    defaultConfig {\n        javaCompileOptions {\n            annotationProcessorOptions {\n                arguments = [\n                    rxhttp_package: 'rxhttp.xxx'\n                ]\n            }\n        }\n    }\n}\n```\n\u003c/details\u003e\n\n\n**Finally, rebuild the project, which is necessary**\n\n2、Initialize the SDK\n\nThis step is optional\n\n```java\nRxHttpPlugins.init(OkHttpClient)  \n    .setDebug(boolean)  \n    .setOnParamAssembly(Consumer)\n    ....\n```\n\n3、Configuration BaseUrl\n\nThis step is optional\n\n```java\npublic class Url {\n\n    //Add the @defaultDomain annotation to BASE_URL\n    @DefaultDomain\n    public static BASE_URL = \"https://...\"\n}\n```\n\n4、Perform the requested\n\n```java\n// java\nRxHttp.get(\"/service/...\")   //1、You can choose get,postFrom,postJson etc\n    .addQuery(\"key\", \"value\")               //add query param\n    .addHeader(\"headerKey\", \"headerValue\")  //add request header\n    .toObservable(Student.class)  //2、Use the toXxx method to determine the return value type, customizable\n    .subscribe(student -\u003e {  //3、Subscribing observer\n        //Success callback，Default IO thread\n    }, throwable -\u003e {\n        //Abnormal callback\n    });\n\n// kotlin \nRxHttp.postForm(\"/service/...\")          //post FormBody\n    .add(\"key\", \"value\")                 //add param to body\n    .addQuery(\"key1\", \"value1\")          //add query param\n    .addFile(\"file\", File(\".../1.png\"))  //add file to body\n    .toObservable\u003cStudent\u003e()           \n    .subscribe({ student -\u003e       \n        //Default IO thread\n    }, { throwable -\u003e\n        \n    })\n\n// kotlin coroutine\nval students = RxHttp.postJson(\"/service/...\")  //1、post {application/json; charset=utf-8}\n    .toAwaitList\u003cStudent\u003e()                          //2、Use the toXxx method to determine the return value type, customizable\n    .await()                                    //3、Get the return value, await is the suspend method\n```\n\n## 3、Advanced usage\n\n 1、Close the request\n\n```java\n//In Rxjava2 , Automatic close request\nRxHttp.get(\"/service/...\")\n    .toObservableString()\n    .as(RxLife.as(this))  //The Activity destroys and automatically closes the request\n    .subscribe(s -\u003e {\n        //Default IO thread\n    }, throwable -\u003e {\n\n    });\n\n//In Rxjava3 , Automatic close request\nRxHttp.get(\"/service/...\")\n    .toObservableString()\n    .to(RxLife.to(this))  //The Activity destroys and automatically closes the request\n    .subscribe(s -\u003e {\n        //Default IO thread\n    }, throwable -\u003e {\n        \n    });\n\n\n//In RxJava2/RxJava3, close the request manually\nDisposable disposable = RxHttp.get(\"/service/...\")\n    .toObservableString()\n    .subscribe(s -\u003e {\n        //Default IO thread\n    }, throwable -\u003e {\n        \n    });\n\ndisposable.dispose(); //Close the request at the appropriate time\n```\n\n## 4、ProGuard\n\nIf you are using RxHttp v2.2.8 or above the shrinking and obfuscation rules are included automatically.\nOtherwise you must manually add the options in [rxhttp.pro](https://github.com/liujingxing/rxhttp/blob/master/rxhttp/src/main/resources/META-INF/proguard/rxhttp.pro).\n\n## 5、Donations\n\nIf this project helps you a lot and you want to support the project's development and maintenance of this project, feel free to scan the following QR code for donation. Your donation is highly appreciated. Thank you!\n\n![donations.png](https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fa6d3941c2c944e59831640fa0ece60d~tplv-k3u1fbpfcp-watermark.image?)\n\n# Licenses\n\n```\nCopyright 2019 liujingxing\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\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":["https://p1-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/fa6d3941c2c944e59831640fa0ece60d~tplv-k3u1fbpfcp-watermark.image"],"categories":["HarmonyOS","Kotlin","网络编程"],"sub_categories":["Windows Manager"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliujingxing%2Frxhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fliujingxing%2Frxhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fliujingxing%2Frxhttp/lists"}