https://github.com/hotstu/tinyritro
仿retrofit 轻量的api请求库
https://github.com/hotstu/tinyritro
android http okhttp3 retrofit
Last synced: 11 months ago
JSON representation
仿retrofit 轻量的api请求库
- Host: GitHub
- URL: https://github.com/hotstu/tinyritro
- Owner: hotstu
- License: apache-2.0
- Created: 2018-05-31T05:21:15.000Z (over 7 years ago)
- Default Branch: master
- Last Pushed: 2021-07-22T08:26:25.000Z (over 4 years ago)
- Last Synced: 2025-01-21T18:33:48.530Z (about 1 year ago)
- Topics: android, http, okhttp3, retrofit
- Language: Java
- Homepage:
- Size: 187 KB
- Stars: 2
- Watchers: 2
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[ ](https://search.maven.org/search?q=g:io.github.hotstu.tinyritro)
[](https://travis-ci.org/hotstu/tinyritro)
[](https://opensource.org/licenses/Apache-2.0)
## tinyritro
轻量的api请求库,基于okhttp3、rxjava2, 使用方式类似retrofit,使用apt,不使用反射,自动完成api请求、json解析,并返回Flowable用于后续调用
## 使用
加入依赖
```java app/build.gradle
annotationProcessor 'io.github.hotstu.tinyritro:compiler:1.0.0'
implementation 'io.github.hotstu.tinyritro:runtime:1.0.0'
implementation 'io.reactivex.rxjava2:rxjava:2.1.8'
implementation 'io.reactivex.rxjava2:rxandroid:2.0.1'
implementation 'com.squareup.okhttp3:okhttp:3.9.1'
implementation 'com.google.code.gson:gson:2.8.2'
```
定义接口
```java
@EntryPoint(value = "http://httpbin.org")
public interface APIService1 {
@Query(path = "/get?id=${id}")
Flowable get(Map params, @PathParam("id") String ids, @PathParam int name);
@Query(method = POST,url = "http://www.example.com/app/open")
Flowable post(Map params);
@Query(method = POST,url = "http://www.example.com/app/open")
Flowable post2(@QueryParam String query1);
}
```
执行build后会根据定义的接口生成调用类tinyritro.java
调用
```java
TinyRitro build = new TinyRitro.Builder().client(OkHttpClientMgr.getInstance()).build();
HashMap params = new HashMap<>();
params.put("aaa", "bbb");
build.getAPIService1().get(params, "233",233)
.compose(RxSchedulers.io_main())
.subscribe(new Consumer() {
@Override
public void accept(String strings) throws Exception {
Log.d("result", "" + strings);
}
}, new Consumer() {
@Override
public void accept(Throwable throwable) throws Exception {
throwable.printStackTrace();
}
});
```
## more about me
|简书| 掘金|JCenter | dockerHub|
| ------------- |------------- |------------- |------------- |
| [简书](https://www.jianshu.com/u/ca2207af2001) | [掘金](https://juejin.im/user/5bee320651882516be2ebbfe) |[JCenter ](https://bintray.com/hglf/maven) | [dockerHub](https://hub.docker.com/u/hglf)|