All Projects → baoshanf → HKHttpManager

baoshanf / HKHttpManager

Licence: MIT license
轻量级的中大型项目AFNetworking高级封装

Programming Languages

objective c
16641 projects - #2 most used programming language
ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to HKHttpManager

Xmnetworking
A lightweight but powerful network library with simplified and expressive syntax based on AFNetworking.
Stars: ✭ 980 (+4800%)
Mutual labels:  afnetworking
Ppnetworkhelper
AFNetworking 3.x 与YYCache封装
Stars: ✭ 1,586 (+7830%)
Mutual labels:  afnetworking
WormholyForObjectiveC
Network debugging made easy,This network debugging tool is developed based on the swift version of Wormholy.
Stars: ✭ 21 (+5%)
Mutual labels:  afnetworking
Hqmnetworking
基于AFN3.x核心类AFURLSessionManager封装的网络请求,支持 HTTPS 请求验证,可以配置请求头,支持多图上传并可选带进度回调,支持 block、delegate(代理) 请求回调,详见
Stars: ✭ 49 (+145%)
Mutual labels:  afnetworking
Wwnetworkhelper
AFN层级更高的网络请求API
Stars: ✭ 111 (+455%)
Mutual labels:  afnetworking
Afnetworking Synchronous
Synchronous requests for AFNetworking 1.x, 2.x, and 3.x
Stars: ✭ 157 (+685%)
Mutual labels:  afnetworking
Webhere
HTML scraping for Objective-C.
Stars: ✭ 16 (-20%)
Mutual labels:  afnetworking
SSJNetWork
对AFNetWorking 二次封装 实现自动取消网络请求,网络请求缓冲,网络请求日志详细打印(代码还有不成熟的地方,如使用请下载到本地使用,如果问题,好及时修改)
Stars: ✭ 31 (+55%)
Mutual labels:  afnetworking
Opensource
♨️ 分享GitHub优秀开源项目和主流开发使用的网站、解决问题方案收集以及学习网站或资料,涵盖了iOS, macOS X, Blockchain, Flutter, Weex, H5, Games, C++, Script等多方面的内容,其中iOS大致包涵以下内容:音视频;IM和直播;逆向开发;图像相关(OpenGL, Metal, GPUImage);内购(IAP), ApplePay和第三方支付;安全攻防和应用加固, 数据安全和算法;常用第三方库;导航栏和状态栏;侧边菜单;数据持久;蓝牙, 手势指纹面容ID解锁, 图片浏览器, 扫码, 下拉和上拉刷新, 指示器, Toast, Menu, Sensor, Privacy, WebView和进度条, 动画, 选择器, 搜索, 分享, 图片验证码, 设备相关信息, 广告, 高仿项目及Demo等。
Stars: ✭ 123 (+515%)
Mutual labels:  afnetworking
Sjnetwork
SJNetwork is a high level network request tool based on AFNetworking and inspired on YTKNetwork.
Stars: ✭ 231 (+1055%)
Mutual labels:  afnetworking
Mvvmdemo
MVVMDemo With ReactiveCocoa
Stars: ✭ 60 (+200%)
Mutual labels:  afnetworking
Lcnetwork
基于AFNetworking的网络库封装
Stars: ✭ 107 (+435%)
Mutual labels:  afnetworking
Zbnetworking
AFNetworking4.X封装 GET/POST /PUT/PATCH /DELETE / Upload /DownLoad 网络请求 添加了请求缓存,断点下载,显示缓存大小,删除缓存,取消当前请求等功能
Stars: ✭ 186 (+830%)
Mutual labels:  afnetworking
Afhttpclientlogger
Configurable HTTP request logger for AFNetworking
Stars: ✭ 40 (+100%)
Mutual labels:  afnetworking
AJNetworking
AFNetworking 3.0 版本的封装,结合MJExtension框架处理JSON序列化问题
Stars: ✭ 35 (+75%)
Mutual labels:  afnetworking
Mhdevelopexample objective c
🔥🔥🔥 iOS开发技术要点汇总,核心功能配备文档。表情键盘布局、大文件分片上传、基于MVC的基类设计、MVVM+RAC实践、微信朋友圈实现方案等。
Stars: ✭ 937 (+4585%)
Mutual labels:  afnetworking
Pgnetworkhelper
PINCache做为AFNetworking缓存层,将AFNetworking请求的数据缓存起来,支持取消当前网络请求,以及取消所有的网络请求,除了常用的Get,Post方法,也将上传图片以及下载文件进行了封装,同样支持同步请求,使用方法极其简单。
Stars: ✭ 131 (+555%)
Mutual labels:  afnetworking
Dotzu-Objective-c
Dotzu Objective-c example project
Stars: ✭ 30 (+50%)
Mutual labels:  afnetworking
GoogleMapsHelper
An easy to integrate Model Based Google Maps Helper (SVHTTPClient, AFNetworking) That lets you Geo Code , Reverse Geocode, Get Directions , Places Autocomplete.
Stars: ✭ 21 (+5%)
Mutual labels:  afnetworking
Afnetworking Retrypolicy
Nice category that adds the ability to set the retry interval, retry count and progressiveness.
Stars: ✭ 197 (+885%)
Mutual labels:  afnetworking

#前言

AFNetworking为我们封装了一系列的网络服务,直接使用基本上可以满足大多数需求。随着需求不断增加,架构不断完善,直接使用AFNetworking未免会代码冗余,于是就出现了各种对AFNetworking的二次封装。 ###现有的AFNetworking二次封装优秀框架

  • YTKNetworking YTKNetwork是基于AFNetworking的高级请求实用,适用于稍微复杂的项目,而不适用于简单的个人项目
  • PPNetworkHelper PPNetworkHelper对AFNetworking 3.x 与YYCache的二次封装,封装常见的GET、POST、文件上传/下载、网络状态监测的功能、方法接口简洁明了,并结合YYCache实现对网络数据的缓存,简单易用,不用再写FMDB那烦人的SQL语句,一句代码搞定网络数据的请求与缓存. 无需设置,无需插件,控制台可直接打印json中文字符,调试更方便
  • XMNetworking XMNetworking是一个轻量的,简单易用但功能强大的网络库 ###一套适合公司业务的网络框架 YTKNetworkingPPNetworkHelper都是面向相对复杂的项目而生,我们没用到缓存部分,同时我们更倾向于轻量级的网络框架。但是我们又崇尚YTKNetworking那样的风格,结合当前项目架构,借鉴 XMNetworking,于是写了能cover住的HKHttpManager

解释 HKHttpManager

HKHttpManagerconfigureloggermanagerresponserequest组成。

  • request的组成
/**
请求 Base URL,优先级高于 [HKHttpConfigure generalServer];
*/
@property (nonatomic, copy) NSString *baseURL;

/**
请求路径 eg: /login2
*/
@property (nonatomic, copy) NSString *requestURL;

/**
请求头,默认为空 @{}
*/
@property (nonatomic, strong) NSDictionary *requestHeader;

/**
请求参数,加密参数 默认为空 @{}
*/
@property (nonatomic, strong) NSDictionary *encryptParams;

/**
请求参数,不用加密 默认为 @{}
*/
@property (nonatomic, strong) NSDictionary *normalParams;

/**
请求方式 默认为 HKRequestTypePost
*/
@property (nonatomic, assign) HKHttpRequestType requestMethod;


/**
请求方式string
*/
@property (nonatomic,copy) NSString *requestMethodName;

/**
请求超时时间 默认 30s
*/
@property (nonatomic, assign) NSTimeInterval reqeustTimeoutInterval;

/**
api 版本号,默认 1.0
*/
@property (nonatomic, copy) NSString *apiVersion;

/**
重试次数,默认为 0
*/
@property (nonatomic, assign) UInt8 retryCount NS_UNAVAILABLE;

/**
生成请求

@return NSURLRequest
*/
- (NSURLRequest *)generateRequest;

三个Request类 以上属性都可以再在初始化之后设置,并且都设置了默认值。同时有些相同的部分你也可以修改generateRequest,无论是chainRequest还是groupRequest都需要以HKHttpRequest为请求requestchainRequestgroupRequest某种意义上都是为了在HKHttpmanager调用方便而封装。

  • HKHttpmanager组成 HKHttpManager主要提供发起请求接口,普通请求可通过block赋值request
/**
直接进行请求,不进行参数及 url 的包装

@param request 请求实体类
@param result 响应结果
@return 该请求对应的唯一 task id
*/
- (NSString *_Nullable)sendRequest:(nonnull HKHttpRequest *)request complete:(nonnull HKHttpResponseBlock) result;


/**
发送网络请求,紧凑型

@param requestBlock 请求配置 Block
@param result 请求结果 Block
@return 该请求对应的唯一 task id
*/
- (NSString *_Nullable)sendRequestWithConfigBlock:(nonnull HKRequestConfigBlock )requestBlock complete:(nonnull HKHttpResponseBlock) result;
  • HKHttpManager+GroupHKHttpManager+Chain 特意将GroupChain封装成了类别,单独处理HKHTTPGroupRequestHKHttpChainRequest并行串行等关系,在这里将request序列化,再调用sendRequest:请求。
- (NSString *)sendGroupRequest:(nullable HKGroupRequestConfigBlock)configBlock
complete:(nullable HKGroupResponseBlock)completeBlock;


- (void)cancelGroupRequest:(NSString *)taskID;
@end

结构图.png

使用 HKHttpManager

#####普通 request

  1. #import "HKHttpManagerHeader.h",建议在APPDelegate初始化baseURL
[HKHttpConfigure shareInstance].generalServer = @"https://www.apiopen.top/";
  1. 根据需要设置公共请求头generalHeaders、公共参数generalParameters
[HKHttpConfigure shareInstance].generalHeaders = @{@"token":token};
[HKHttpConfigure shareInstance].generalParameters = @{@"openid":@"xxx"};
  1. 构建request
HKHttpRequest *request = [[HKHttpRequest alloc] init];
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"1"
};
request.requestMethod = HKHttpRequestTypeGet;

4.发起请求

[[HKHttpManager shareManager] sendRequest:request complete:^(HKHttpResponse * _Nullable response) {
NSLog(@"%@",response.content);
}];

或者在block里构建request

[[HKHttpManager shareManager] sendRequestWithConfigBlock:^(HKHttpRequest * _Nullable request) {
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"1"
};
request.requestMethod = HKHttpRequestTypeGet;
} complete:^(HKHttpResponse * _Nullable response) {
if (response.status == HKHttpResponseStatusSuccess) {
NSLog(@"%@",response.content);
}
}];

#####使用chainQequest实现链式请求

[[HKHttpManager shareManager] sendChainRequest:^(HKHttpChainRequest * _Nullable chainRequest) {
[chainRequest onFirst:^(HKHttpRequest * _Nullable request) {
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"1"
};
request.requestMethod = HKHttpRequestTypeGet;
}];
[chainRequest onNext:^(HKHttpRequest * _Nullable request, HKHttpResponse * _Nullable responseObject, BOOL * _Nullable isSent) {
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"2"
};
request.requestMethod = HKHttpRequestTypeGet;
}];
[chainRequest onNext:^(HKHttpRequest * _Nullable request, HKHttpResponse * _Nullable responseObject, BOOL * _Nullable isSent) {
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"3"
};
request.requestMethod = HKHttpRequestTypeGet;
}];

} complete:^(NSArray<HKHttpResponse *> * _Nullable responseObjects, BOOL isSuccess) {

}];

####使用groupQequest实现无序批量请求

[[HKHttpManager shareManager] sendGroupRequest:^(HKHttpGroupRequest * _Nullable groupRequest) {
for (NSInteger i = 0; i < 5; i ++) {
HKHttpRequest *request = [[HKHttpRequest alloc] init];
request.requestURL = @"satinApi";
request.normalParams = @{@"type":@"1",
@"page":@"1"
};
request.requestMethod = HKHttpRequestTypeGet;
[groupRequest addRequest:request];
}
} complete:^(NSArray<HKHttpResponse *> * _Nullable responseObjects, BOOL isSuccess) {

}];

##TODO HKHttpManager目前能满足公司的业务,但是许多细节方面还需优化,例如:

  1. 实现断点续传
  2. groupRequestchainRequestrequest一致,支持两种请求方式(目前只能在block中对groupRequestchainRequest赋值)。
  3. configure这方面还需要优化,增加对request默认请求的配置 #End GitHub地址在这里: HKHttpManager 谢谢各位阅读,能力有限,希望大家能多提点优化建议和看法!
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].