Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

✈️ android async http simple wrapper with cache policy for rest api

License

NotificationsYou must be signed in to change notification settings

dtboy1995/android-sex-http

Repository files navigation

android-sex-http

android-sex-httpBuild Status

✈️ android async http simple wrapper with cache policy

install

implementation'org.ithot.android.transmit:http:0.3.2'

usage

  • permissions

  <uses-permissionandroid:name="android.permission.INTERNET" />  <uses-permissionandroid:name="android.permission.ACCESS_NETWORK_STATE" />
  • jsonserializer

implementation'org.ithot.android.serializer:gson:1.0.1'
  • sample

publicclassDummy {publicStringid;}
// init onceReq.init(context,newJSON());// send requestReq.build(context)   .url("https://ithot.org/dummy")   .res(newRes<Dummy>(){@Overridepublicvoidok(Header[]headers,Dummyresponse) {     }@Overridepublicvoidno(Header[]headers,Stringerror) {     }   })   .go();
  • config

// default http 80 https 443Req.init(context,serialier);// set http portReq.init(context,3000,serialier);// set https portReq.init(context,3000,5000,serialier)// set base url example for https://api.somedomain.comReq.base("https://ithot.org");// distinguish different users requestReq.prefix("user_id");// if true log response default falseReq.debug(true);// http lifecycle hooksReq.hook(newIHTTPHook(){// no network call this hook@Overridepublicvoiddisconnected(Contextcontext) {  }// you can set common headers@OverridepublicList<Header>headers() {  }// before request call this hook, you can display a dialog@Overridepublicvoidpre(Contextcontext) {  }// request done call this hook, you can dismiss a dialog@Overridepublicvoidpost(Contextcontext) {  }// abnormal response call this hook@Overridepublicvoidfail(Header[]headers,Stringresponse,Contextcontext) {  }});
  • custom json serializer

publicclassSerializerextendsJSONSerializer {// you can use any serialization library such as Gson Fastjson etc example belowprivateGsongson =newGson();@OverridepublicObjectparse(Stringjson,Typetype) {returngson.fromJson(json,type);    }@OverridepublicStringstringify(Objectobject) {returngson.toJson(object);    }}Req.init(context,newSerializer());
  • download (break restoration)

<uses-permissionandroid:name="android.permission.READ_EXTERNAL_STORAGE" /><uses-permissionandroid:name="android.permission.WRITE_EXTERNAL_STORAGE" />
Filefile =newFile(Environment.getExternalStorageDirectory() +File.separator +"test.mp3");Req.build(context)   .base(false)   .url("https://ithot.org/music")   .res(newFileRes() {@Overridepublicvoiddone(Filef) {        }@Overridepublicvoidundone() {        }@Overridepublicvoidprogress(intrate) {        }    })  .download(file);

About

✈️ android async http simple wrapper with cache policy for rest api

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages


[8]ページ先頭

©2009-2025 Movatter.jp