All Projects → open-android → Retrofitutils

open-android / Retrofitutils

retrofit网络工具类

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Retrofitutils

RetrofitHelper
💪 RetrofitHelper是一个支持配置多个BaseUrl,支持动态改变BaseUrl,动态配置超时时长的Retrofit帮助类
Stars: ✭ 15 (-92.02%)
Mutual labels:  retrofit, retrofit2
Android Kotlin Mvi Cleanarchitecture
Android + Kotlin + Modularization + Gradle Depedency managment + Gradle written in Kotlin DSL + Custom Gradle Plugin + MVVM + MVI + Clean Architecture + Repository Pattern + Coroutines + Flows + Koin + Retrofit2 + ROOM + Kotlin-Android-Extension + KtLints
Stars: ✭ 187 (-0.53%)
Mutual labels:  retrofit, retrofit2
uv-index
This is a work-in-progress (🔧️) ultraviolet index viewer app for demonstrating Instant Apps + Kotlin + Dagger + MVP
Stars: ✭ 64 (-65.96%)
Mutual labels:  retrofit, retrofit2
WanAndroid
wanandroid的Kotlin版,采用Android X
Stars: ✭ 20 (-89.36%)
Mutual labels:  retrofit, retrofit2
Bigbang
Android base project used by Xmartlabs team
Stars: ✭ 47 (-75%)
Mutual labels:  retrofit, retrofit2
RxHttp
基于RxJava2+Retrofit+OkHttp4.x封装的网络请求类库,亮点多多,完美兼容MVVM(ViewModel,LiveData),天生支持网络请求和生命周期绑定,天生支持多BaseUrl,支持文件上传下载进度监听,支持断点下载,支持Glide和网络请求公用一个OkHttpClient⭐⭐⭐
Stars: ✭ 25 (-86.7%)
Mutual labels:  retrofit, retrofit2
tuya-connector
tuya-connector helps you efficiently create cloud development projects regarding the OpenAPI or message subscription capabilities. You can put all the focus on business logic without taking care of server-side programming nor relational databases.
Stars: ✭ 28 (-85.11%)
Mutual labels:  retrofit, retrofit2
rxjava2 retrofit2
rxjava2+retrofit2 网络封装
Stars: ✭ 19 (-89.89%)
Mutual labels:  retrofit, retrofit2
Kotlin Coroutines Retrofit
Kotlin Coroutines await() extension for Retrofit Call
Stars: ✭ 812 (+331.91%)
Mutual labels:  retrofit, retrofit2
Mvvmhabit
goldze: 本人喜欢尝试新的技术,以后发现有好用的东西,我将会在企业项目中实战,没有问题了就会把它引入到MVVMHabit中,一直维护着这套框架,谢谢各位朋友的支持。如果觉得这套框架不错的话,麻烦点个 star,你的支持则是我前进的动力!
Stars: ✭ 6,789 (+3511.17%)
Mutual labels:  retrofit, retrofit2
StatefulLiveData
StatefulLiveData is a lean, yet powerful tool that harnesses the capabilities of LiveData and enhances them, enabling the observer to distinguish between different states the data can be in, such as Success, Loading and Error.
Stars: ✭ 18 (-90.43%)
Mutual labels:  retrofit, retrofit2
Kotlinmvparchitecture
Clean MVP Architecture with Dagger2 + Retrofit2 + Mockito + Fresco + EasiestGenericRecyclerAdapter using Kotlin. Added Unit Tests(Kotlin Tests)!
Stars: ✭ 143 (-23.94%)
Mutual labels:  retrofit, retrofit2
EasyRetro
An Easy to use retrofit based network/api call extention for android
Stars: ✭ 16 (-91.49%)
Mutual labels:  retrofit, retrofit2
Easyhttp
Android 网络请求框架,简单易用,so easy
Stars: ✭ 423 (+125%)
Mutual labels:  retrofit, retrofit2
Githubapp
A showcase app showing how to use PagingLibrary with Retrofit, Coroutines, Koin & Testing.
Stars: ✭ 124 (-34.04%)
Mutual labels:  retrofit, retrofit2
Retrofiturlmanager
🔮 Let Retrofit support multiple baseUrl and can be change the baseUrl at runtime (以最简洁的 Api 让 Retrofit 同时支持多个 BaseUrl 以及动态改变 BaseUrl).
Stars: ✭ 1,961 (+943.09%)
Mutual labels:  retrofit, retrofit2
Wanandroid
玩安卓客户端(Java版)
Stars: ✭ 166 (-11.7%)
Mutual labels:  retrofit
Newsapp
A Sample News App written in Kotlin using Android Architecture Components, MVVM
Stars: ✭ 179 (-4.79%)
Mutual labels:  retrofit2
Coroutines Flows Modularised
Clean Architecture Modular Project: MVVM + Coroutines+ Flows + Dagger2 + LiveData + UnitTests + UITests + MockWebServer
Stars: ✭ 166 (-11.7%)
Mutual labels:  retrofit2
Stepik Android
Android Application for Taking Open Courses on the Stepik Platform
Stars: ✭ 165 (-12.23%)
Mutual labels:  retrofit2
  • 欢迎关注微信公众号,长期推荐技术文章和技术视频

  • 微信公众号名称:Android干货程序员

PS:如果觉得文章太长,你也可观看该课程的视频教程,亲,里面还有高清,无码的福利喔

写在前面: Retrofit与okhttp共同出自于Square公司,是目前市场上使用最多的联网框架,retrofit是对okhttp做了一层封装,不过封装之后的retrofit上手还是极其复杂,为了解决使用难度问题,本文推荐使用github开源项目RetrofitUtils.


{  
"code": 1,  
"message": "success",  
"result": {  
"items": [  
    {  
        "detail": "",  
        "href": "http://www.oschina.net/news/79650/2017-top-programming-languages",  
        "id": 79650,  
        "img": "https://static.oschina.net/uploads/cooperation/75410/google-beta-natural-language-api_048424e4-a8c3-41e8-91ef-aa009e3fc559.jpg",  
        "name": "2017 年热门编程语言排行榜",  
        "pubDate": "2016-12-06 11:51:24",  
        "type": 6  
        },  
    {  
        "detail": "",  
        "href": "https://www.oschina.net/question/2720166_2210842",  
        "id": 2210842,  
        "img": "https://static.oschina.net/uploads/cooperation/75323/ubuntu-forum-black-sql_eb9137ea-efb2-49aa-99fd-025a221dcfe7.jpg",  
        "name": "高手问答 | MySQL 开发和运维规范",  
        "pubDate": "2016-12-06 15:48:10",  
        "type": 2  
    },  
    {  
        "detail": "",  
        "href": "http://www.oschina.net/news/79757/tiobe-12",  
        "id": 79757,  
        "img": "https://static.oschina.net/uploads/cooperation/78083/chrome55-save-at-least-35-percent-memory_70ceba24-eb96-4710-99ec-c1cb5a26a3d6.jpg",  
        "name": "C 语言为何一蹶不振?",  
        "pubDate": "2016-12-08 15:18:20",  
        "type": 6  
    },  
    {  
        "detail": "",  
        "href": "https://www.oschina.net/news/79732/firebug-stop-develope-and-maintain",  
        "id": 79732,  
        "img": "https://static.oschina.net/uploads/cooperation/77929/top-income-programming-languages-2016_16e9be1b-2a6b-453f-bafa-442fd043024b.jpg",  
        "name": "Firebug 宣布不再维护,讲不出再见!",  
        "pubDate": "2016-12-08 10:56:47",  
        "type": 6  
    },  
    {  
        "detail": "",  
        "href": "http://www.oschina.net/news/79673/the-founder-of-cm-was-fired",  
        "id": 79673,  
        "img": "https://static.oschina.net/uploads/cooperation/78455/intellij-idea-2016-3-public-preview_63725513-45e4-4fb2-a0bf-c7940a7a87bc.jpg",  
        "name": "Cyanogen 之父被踢出局",  
        "pubDate": "2016-12-06 11:48:43",  
        "type": 6  
    }],  
    "nextPageToken": "61AF0C190D6BD629",  
    "prevPageToken": "3EA621243546C8A5",  
    "requestCount": 5,  
    "responseCount": 5,  
    "totalResults": 5  
},  
  "time": "2016-12-13 10:56:41"}  
  • 这样一个接口我看看使用RetrofitUtils该如何使用

1.png

大家看简单实用只需要new一个request然后发送一个send请求,就能返回服务器的数据,并且压根不需要解析拿到的直接就是各位需要的bean对象.那么我们来看看RetrofitUtils的使用步骤

在project的build.gradle添加如下代码(如下图)

jitpack.png

引入当前项目

compile 'com.github.open-android:RetrofitUtils:0.1.9'

在清单文件添加如下权限

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

新建Application类并且在oncreate方法当中进行初始化: 千万注意Application记得在manifest.xml中注册。

  ItheimaHttp.init(this, Urls.getBaseUrl());

eg:请求地址:http://www.oschina.net/action/apiv2/banner?catalog=1

那么baseUrl = http://www.oschina.net RetrofitUtils内部封装了如下使用方法

看一个完整Get和Post请求是如何实现:异步请求(内部使用Gson解析json数据)直接返回实体bean对象

Request request = ItheimaHttp.newGetRequest(apiUrl);//apiUrl格式:"xxx/xxxxx"  
Call call = ItheimaHttp.send(request, new HttpResponseListener<Bean>() {  
    @Override  
    public void onResponse(Bean bean) {  
    ........  
    }  
     /** 
     * 可以不重写失败回调 
     * @param call 
     * @param e 
     */  
    @Override  
    public void onFailure(Call<ResponseBody> call, Throwable e) {  
    ......  
    }  
});  
@param httpResponseListener 回调监听  
@param <T> Bean  
@return Call可以取消网络请求</span>  

添加请求参数

request.putParams(key,value)  
.putParams(key,value)  
.putParams(key,value);  


Map<String,Object> map = new HashMap<>();  
map.put(key,value);  
request.putParamsMap(map);  

添加请求头

request.putHeader(key,value)  
.putHeader(key,value);

如果不需要RetrofitUtils框架自动解析json,那么可以使用如下请求

Call call = ItheimaHttp.getAsync(apiUrl, new HttpResponseListener<String>);  

Call call = ItheimaHttp.postAsync(apiUrl, new HttpResponseListener<String>() {  
    @Override  
    public void onResponse(String s) {  
    ........  
    }  
});

如果需要RetrofitUtils框架自动解析json,直接获取javabean,那么可以使用如下请求

Call call = ItheimaHttp.getAsync(apiUrl, new HttpResponseListener<Bean>);  

Call call = ItheimaHttp.postAsync(apiUrl, new HttpResponseListener<Bean>() {  
    @Override  
    public void onResponse(Bean bean) {  
    ........  
    }  
});

文件上传

Request request = ItheimaHttp.newUploadRequest("http://xxx/xxx/xxx", RequestMethod.POST);  
request.putUploadFile(uploadFile).putMediaType(MediaType.parse("multipart/form-data"));  
ItheimaHttp.upload(request, new UploadListener() {  
    @Override  
    public void onResponse(Call call, Response response) {  
    //上传成功回调  
    }  
    
    @Override  
    public void onProgress(long progress, long total, boolean done) {  
    //上传进度回调progress:上传进度,total:文件长度, done:上传是否完成  
    }  
    
    @Override  
    public void onFailure(Call call, Throwable t) {  
    //上传失败  
    }  
});

取消网络请求

call.cancel();
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].