flux-retrofit-okhttp封装
来源:互联网 发布:段奕宏 知乎 编辑:程序博客网 时间:2024/05/27 01:29
经过一段时间对flux的研究有些个人的体会,具体参考flux
这次介绍基于retrofit和okhttp和数据流的单向流动来刷新界面。更多okhttp使用参考
介绍基于flux数据传递:
1.通过retrofit和okhttp加载网络数据通过gson解析成java对象,在flux的模式下进行刷新界面,传递数据。
2.通过action creator加载数据–>
3.通过dispatcher发送数据(action封装数据)–>
4.store–>通过dispatcher发送数据(action封装数据)–>
5.到界面层(调用store中的数据更新界面)
具体流程参考demo;
以下介绍retrofit中的网络请求方式:
// get 请求可使用如下方式 // 在weather后面拼接请求参数 @GET("weather") Call<Weather> getWeather(@Query("location") String location, @Query("output") String output, @Query("ak") String ak); //================================================================= // 以下使用方式来自官网[http://square.github.io/retrofit/](http://square.github.io/retrofit/) // 直接请求接口 @GET("weather/list") Call<Weather> getWeather(); // 不用注解形式,手动拼接参数 @GET("weather/list?sort=desc") Call<Weather> getWeathers(); // 注解形式,替换{id}中的值来构建url @GET("weather/{id}/weathers") Call<List<Weather>> getWeather(@Path("id") int weatherId); // 注解形式,替换{id}中的值来构建url,并拼接请求参数 @GET("weather/{id}/weathers") Call<List<Weather>> getWeather(@Path("id") int weatherId, @Query("sort") String sort); // 注解形式,替换{id}中的值来构建url,并拼接多个请求参数 @GET("weather/{id}/weathers") Call<List<Weather>> getWeather(@Path("id") int weatherId, @QueryMap Map<String, String> options); //====================================================== // post 请求方式如下 // 以下是自定义请求体 // 指定自定义请求体需要使用一个转换器,转换改造实例自定义body。如果没有添加转换器,只能使用RequestBodycan。 @POST("Weather/new") Call<Weather> createUser(@Body Weather user); // forum表单提交方式,用@Field添加表单中的请求字段 @FormUrlEncoded// 对请求url进行编码 @POST("Weather/edit") Call<Weather> updateWeather(@Field("first_name") String first, @Field("last_name") String last); // forum表单提交方式,用@FieldMap添加多个请求字段类似于@QueryMap @FormUrlEncoded// 对请求url进行编码 @POST("Weather/edit") Call<Weather> updateWeather(@FieldMap Map<String, String> options); //====================================================== // PUT 多部分,分块请求方式如下 // 多部分请求时使用@Part注释声明,同时我们也可以继承RequestBody实现我们自定义的requestbody @Multipart @PUT("Weather/photo") Call<Weather> updateWeather(@Part("photo") RequestBody photo, @Part("description") RequestBody description); // 多部分请求时使用@PartMap注释声明。 @Multipart @PUT("Weather/photo") Call<Weather> updateWeathers(@PartMap Map<String, RequestBody> options); //====================================================== // 定义的请求头使用@Headers注解 // 每个请求的header不会相互覆盖,即使有同名的名称的请求也会添加到请求的request中去的。 // 如果请求头中对应的值是null,此header就回被忽略了 @Headers("Cache-Control: max-age=640000")// 自定义缓存时间 @GET("widget/list") Call<List<Weather>> widgetList(); // 添加多个请求头 @Headers({ "Accept: application/vnd.github.v3.full+json", "User-Agent: Retrofit-Sample-App" }) @GET("users/{username}") Call<Weather> getUser(@Path("username") String username);
下面提供项目源码下载地址
以上仅个人想法如有不足错误,欢迎留言讨论指教。
1 0
- flux-retrofit-okhttp封装
- 封装RxJava+Retrofit+OkHttp
- okhttp封装与Retrofit对比
- Retrofit对OKhttp的封装
- Retrofit+OKhttp+RxJava框架的封装
- RxJava+okhttp+Retrofit+Mvp 的封装
- Rxjava+ReTrofit+okHttp深入浅出-终极封装
- RxJava+Retrofit+OkHttp 深入浅出-终极封装一
- 终极封装 Rxjava+Retrofit+okhttp+mvp实现
- RxJava + Retrofit + OKHttp + RxLifecycle进一步封装网络
- Retrofit和OkHttp简单的二次封装
- 封装Retrofit + okhttp + rxjava网络请求框架
- OKhttp+Retrofit
- Retrofit的简单封装--更方便的配置okhttp
- RxJava+Retrofit+OkHttp深入浅出-终极封装二(网络请求)
- 基于Retrofit、OkHttp、Gson封装通用网络框架
- RxJava+Retrofit+OkHttp深入浅出-终极封装三(文件上传)
- Rxjava+ReTrofit+okHttp深入浅出-终极封装三(文件上传)
- Linux中vi显示中文乱码的问题
- linux下vsftpd服务与tftp服务有什么不同
- Webx之csrf攻击
- 64-Unique Binary Search Trees
- android 各版本发布时间
- flux-retrofit-okhttp封装
- 一个复杂的SQL存储过程例子
- 阅读程序补充-1
- Python 模版引擎
- mesos+docker集群之zookeeper
- 关于butterknife8.01 报空指针
- dxp 使用
- Linux swap清理
- 第十一周阅读项目(1)