An open API service indexing awesome lists of open source software.

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请求库

Awesome Lists containing this project

README

          

[![Download](https://img.shields.io/maven-central/v/io.github.hotstu.tinyritro/runtime?style=flat-square) ](https://search.maven.org/search?q=g:io.github.hotstu.tinyritro)
[![Build Status](https://travis-ci.org/hotstu/tinyritro.svg?branch=master)](https://travis-ci.org/hotstu/tinyritro)
[![License](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](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)|