GithubHelp home page GithubHelp logo

tinyritro's Introduction

Download Build Status License

tinyritro

轻量的api请求库,基于okhttp3、rxjava2, 使用方式类似retrofit,使用apt,不使用反射,自动完成api请求、json解析,并返回Flowable用于后续调用

使用

加入依赖

    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'

定义接口

@EntryPoint(value = "http://httpbin.org")
public interface APIService1 {
    @Query(path = "/get?id=${id}")
    Flowable<String> get(Map<String, String> params, @PathParam("id") String ids, @PathParam int name);

    @Query(method = POST,url = "http://www.example.com/app/open")
    Flowable<Person> post(Map<String, String> params);

    @Query(method = POST,url = "http://www.example.com/app/open")
    Flowable<Person> post2(@QueryParam String query1);
}

执行build后会根据定义的接口生成调用类tinyritro.java 调用

        TinyRitro build = new TinyRitro.Builder().client(OkHttpClientMgr.getInstance()).build();
        HashMap<String, String> params = new HashMap<>();
        params.put("aaa", "bbb");
        build.getAPIService1().get(params, "233",233)
                .compose(RxSchedulers.<String>io_main())
                .subscribe(new Consumer<String>() {
                    @Override
                    public void accept(String strings) throws Exception {
                        Log.d("result", "" + strings);
                    }
                }, new Consumer<Throwable>() {
                    @Override
                    public void accept(Throwable throwable) throws Exception {
                        throwable.printStackTrace();
                    }
                });

more about me

简书 掘金 JCenter dockerHub
简书 掘金 JCenter dockerHub

tinyritro's People

Contributors

hotstu avatar

Stargazers

tianshui avatar Wade avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.