• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

RestVolley: A Http request framework based on Volley and OkHttp that supports re ...

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称:

RestVolley

开源软件地址:

https://gitee.com/firefly_osc/RestVolley

开源软件介绍:

RestVolley


A http request engine based on Volley and OkHttp, giving up Apache HttpClient request. supports image loading, restful api requesting, and file downloading. READ MORE

Dependency


binary on jcenter

dependent with Maven:

<dependency>  <groupId>com.hujiang.restvolley</groupId>  <artifactId>restvolley</artifactId>  <version>1.0.1</version></dependency>

or Gradle:

compile 'com.hujiang.restvolley:restvolley:1.0.1'

Functions


Restful API request

RestVolley make restful API requesting conveniently.It support the most http method request, such as GET,HEAD,POST,DELETE,OPTIONS,PATCH,PUT,TRACE.

GETPOSTDELETEPUTHEADPATCHOPTIONSTRACE
CacheableYNNNYNYY
requireBodyNYNYNYNN
permitBodyY
  • create a request
//Get requestnew GetRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//post requestnew PostRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Delete requestnew DeleteRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Put requestnew PutRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Head requestnew HeadRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Patch requestnew PatchRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Options requestnew OptionsRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());//Trace requestnew TraceRequest(context).url("").execute(String.class, new RestVolleyCallback<String>());
  • set http request params: header, urlparams, requestbody, contentType, charset
new GetRequest(context).url("")	.setTag("")	.setRetryPolicy(new DefaultRetryPolicy())	.setShouldCache(true)	.setPriority(Priority.Normal)	//default is "application/json"	.setContentType("application/json")	//default is "UTF-8"	.setCharset("UTF-8")	.addHeader("userId", "12345")	.addHeaders(map)	.setUserAgent("")	.addParams(key, value)	.setCacheEntry(...)	.execute(.....);
  • Cache
//default falsesetShouldCache(true);setCacheEntry(...)
  • RetryPolicy
setRetryPolicy(new DefaultRetryPolicy())
  • Priority
//default is Priority.NormalsetPriority(Priority.Normal)
  • ContentType and Charset
	//default is "application/json"	setContentType("application/json")	//default is "UTF-8"	setCharset("UTF-8")
  • Tag
setTag(tag);
  • UserAgent
setUserAgent("")
  • timeout
setConnectTimeout(...);setReadTimeout(...);setWriteTimeout(...);//for all timoutsetTimeout(...);
  • header
addHeader(key, value);//oraddHeaders(map);
  • params
//add url paramsaddParams(key, value);//for post/put/patch or deleteaddParams(key, file);addParams(key, inputstream);
  • body and HttpEntity
//body and HttpEntity for post/put/patch or deletesetBody(byte[] bytes);setBody(HttpEntity httpEntity);setBody(String s);//convert params to form data entity.paramsToFormEntity();//convert params to json entity.paramsToJsonEntity();//convert params to multipart entity.paramsToMultipartEntity();
  • execute and syncExecute
//async execute with callback.new GetRequest(context).url().execute(String.class, new RestVolleyCallback<String>());//sync execute.RestVolleyResponse<String> response = new GetRequest(context).url().syncExecute(String.class);
  • request with new RequestEngine

suggest using the default RequestEngine, only if the request need proxy.

//new GetRequest(context).setRequestEngine(...);//create a new RequestEngineRestVolley.newRequestEngine(context, engineTag);

Image load

RestVolleyImageLoader has memory cache and disk cache, supports not only network image request, but sdcard/assets/res/ContentProvider Uri image request, uri scheme like:

http/httpshttp://www.google.com/xxx/xxx.png
filefile:///mnt/sdcard/xxx.png
assetsassets://assets_default.png
res“drawable://” + R.drawable.drawable_default, or "drawable://" + R.raw.defaut
ContentProvidercontent://media/external/images/media/27916
  • set global config
RestVolleyImageLoader.instance(context).setConfig(ImageLoaderGlobalConfig cfg);
  • ImageLoaderGlobalConfig
ImageLoaderGlobalConfig.create().memCacheSize(..).diskCacheSize(..).diskCacheDir(..).requestEngine(..);
  • ImageLoadOption
ImageLoadOption.create().defaultImgResId(..)	.errorImgResId(..)	.imgLoadAnimation(..)	.scaleType(..)	.maxWidth(..)	.maxHeight(..)	.cacheEnable(..);
  • displayImage
RestVolleyImageLoader.instance(context).displayImage(uri, imageView);//RestVolleyImageLoader.instance(context).displayImage(uri, imageView, imageLoadOption);
  • loadImage
RestVolleyImageLoader.instance(context).loadImage(uri, ImageListener);//RestVolleyImageLoader.instance(context).loadImage(uri, ImageLoadOption, ImageListener);
  • syncLoadImage
RestVolleyImageLoader.instance(context).syncLoadImage(String uri);//RestVolleyImageLoader.instance(context).syncLoadImage(uri, ImageLoadOption);
  • others
RestVolleyImageLoader.instance(context).isCached(...);RestVolleyImageLoader.instance(context).removeCache(...);

File download

new RestVolleyDownload(context)	.url(url)	.addHeader(key, value)	.tag(tag)	.setProxy(...)	.setTimeout(...)	.setIsAppend(..)	.download(......)	//or	.syncdownload(....)

simple static download.

RestVolleyDownload.download(....)//orRestVolleyDownload.syncDownload(....)

Data upload

Using RestVolleyUpload as PostRequest.

new RestVolleyUpload(context).url(..).execute(...);//ornew RestVolleyUpload(context).url(..).syncExecute(...);

License


Copyright (C) 2016 Hujiang, Inc.Copyright (C) 2014 Xiaoke Zhang.Copyright (C) 2011 The Android Open Source Project.Copyright (C) 2016 Square, Inc.Licensed under the Apache License, Version 2.0 (the "License");you may not use this file except in compliance with the License.You may obtain a copy of the License at   http://www.apache.org/licenses/LICENSE-2.0Unless required by applicable law or agreed to in writing, softwaredistributed under the License is distributed on an "AS IS" BASIS,WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.See the License for the specific language governing permissions andlimitations under the License.

Change Log


  • 1.0.1

    1. fix bintrayUpload error
  • 1.0.0

    1. release for rest api requesting, image loading, downloading, uploading.

鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap