Last year I wrote Novate, an Android networking framework, which is a chained networking framework based on Retrofit and RxJava encapsulation. It supports partitioning of okHTTP calls, is compatible with Retrofit injection, and supports chained operations of RxJava calls. Still use Okhttp’s efficient network loading! The most important exception driver mechanism of Novate helps developers solve most of the exception error processing and reduces the crash probability caused by API or business code errors.


function

  • Optimized design: Add basic API to reduce API redundancy

  • Powerful cache mode: Support offline cache, no intelligent network load cache, you can configure whether to cache

  • Cookie management: Provides a built-in cookie management mechanism

  • Omnidirectional request mode: Supports multiple access methods (GET, PUT, POST,delete)

  • Light send call: support form, text and text together, JSON upload.

  • File transfer: Support file download and upload, support progress

  • Dynamic add: Request headers and parameters can be added separately.

  • Result processing: support unified processing of returned results, automatically help you serialize complex data.

  • Scalability: Support for custom Retrofit apis, and customize your own Service when the default API is not available

  • Elegant and convenient: support unified request access network process control, to help you perfectly join Processbar progress.

  • RxJava combine: Combine RxJava, thread intelligent control

integration

Gradle:

  • Root:

    repositories { maven { url “https://jitpack.io” } jcenter() }

  • app:

       dependencies {
          compile 'com. Tamic. Novate: novate: 1.5.4.3'
       }Copy the code

RxAPi

RxGet, RxPost, RxDelete,RxPut, RxBody,RxFrom, RxUpLoad,RxDownLoad. Read the introduction to RxCallBack before using the basic APi.

RxGet

RxCallBack (RxCallBack); RxCallBack (RxCallBack); RxCallBack (RxCallBack);

Basic use:

Returns a String

New novate.builder (this).baseurl (" www.xxx.com/ ").build().rxget ()"service/path", parameters, new RxStringCallback() {});Copy the code

Return the Bean

 novate.rxGet("path or url", parameters, new RxResultCallback<JavaBean>() {
       
    });Copy the code

Returning to the List

    new Novate.Builder(this)
            .baseUrl("http://xxx.com/")
            .build()
            .rxGet("service/getList", parameters, new RxListCallback<List<JavaBean>>() {
              ...
            });Copy the code

Returns the File

novate.rxGet("path or url", null, new RxFileCallBack(filePath, "name.jpg") {... });Copy the code

RxPost:

Post request invocation

Returns a String

   novate.rxPost("path or url", parameters, new RxStringCallback() {... });Copy the code

Return the Bean

 novate.rxPost("path or url", parameters, new RxResultCallback<ResultModel>() {
  
 
 });Copy the code

Returning to the List

 novate.rxPost("path or url", parameters, new RxListCallback<List<ResultModel>>() {

       ....

    });Copy the code

Returns the File

 novate.rxPost("path or url", null, new RxFileCallBack(filePath, "name.jpg") {... });Copy the code

Upload a file



Here is how to upload files using Novate:

Novate provides two ways to upload files. Body and Part modes, body does not contain the key value, and part contains the key value.

RxUploadWithBody

Post data in Body mode, can report files, pictures, etc.

   String mPath = uploadPath; //"you File path ";
    String url = "http:/xxx.com";

    novate.rxUploadWithBody(url, new File(mPath), new RxStringCallback() {... }); }Copy the code

RxUploadWithPart

Upload files. The default key is image

   String mPath = uploadPath; //"you File path ";
   String url = "http:/xxx.com";
   File file = new File(mPath);
   novate.rxUploadWithPart(url, file, new RxStringCallback() {... });Copy the code

Upload multiple files:

RxUploadWithPartListByFile:

   List<File> fileList = new ArrayList<>();
    fileList.add(file);
    fileList.add(file);
    fileList.add(file);
    novate.rxUploadWithPartListByFile(url, fileList, new RxStringCallback() {});Copy the code

Graphic together

   
   RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
      .addFormDataPart("key1", V1)
      .addFormDataPart("key2", v2)
      .addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file))
      .build();
   novate.rxBody(url , requestBody, callback);Copy the code

RxBody

 
   RequestBody requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM)
      .addFormDataPart("key1", V1)
      .addFormDataPart("key2", v2)
      .addFormDataPart("file", file.getName(), RequestBody.create(MediaType.parse("image/*"), file))
      .build();
   
  novate.rxBody(url , requestBody, callback);Copy the code

The download file

Download with rxGet() :

  String downUrl = "http://wap.dl.pinyin.sogou.com/wapdl/hole/201512/03/SogouInput_android_v7.11_sweb.apk";

  novate.rxGet(downUrl, parameters, new RxFileCallBack(FileUtil.getBasePath(this), "test.apk") {});Copy the code

Download RxDown ()

    String downUrl = "http://wap.dl.pinyin.sogou.com/wapdl/hole/201512/03/SogouInput_android_v7.11_sweb.apk";
    new Novate.Builder(this)
            .rxDownload(downUrl, new RxFileCallBack(FileUtil.getBasePath(this), "test.apk") {});Copy the code

OkHTTP posture

Those who like okhtP poses can continue to use them:

  Request request =
            new Request.Builder()
                    .get()
                    .url("you url")
                    .build();

    novate.execute(request, new RxStringCallback() {});Copy the code


Retrofit Api posture

If the default Novate API bothers you, Novate also supports your own ApiService from Retrofit.

Define APi as Retrofit’s APi

New MyApi


 public interface MyApi {

  @GET("url")
  Observable<MyBean> getdata(@QueryMap Map<String, String> maps);

 }Copy the code

Execute

Call the Call ()

 MyApi myApi = novate.create(MyApi.class);

 novate.call(myApi.getdata(parameters),
            new BaseSubscriber<MyBean>{
            ' '' '' ''}); }Copy the code


For more API, go to Github (github.com/Tamicer/Nov…) Read welcome star! Have doubt can leave a message directly or raise issues, or add QQ group 45854294 consultation.