{"id":20200177,"url":"https://github.com/mxabc/lbxnetwork","last_synced_at":"2025-04-10T11:13:00.504Z","repository":{"id":56918157,"uuid":"135695531","full_name":"MxABC/LBXNetwork","owner":"MxABC","description":"iOS轻量级http请求封装，基于AFNetworking4.x+YYCache","archived":false,"fork":false,"pushed_at":"2021-04-27T08:33:07.000Z","size":149,"stargazers_count":11,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-23T16:04:10.614Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/MxABC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-06-01T09:11:06.000Z","updated_at":"2021-09-30T07:44:18.000Z","dependencies_parsed_at":"2022-08-20T21:20:27.501Z","dependency_job_id":null,"html_url":"https://github.com/MxABC/LBXNetwork","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MxABC%2FLBXNetwork","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MxABC%2FLBXNetwork/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MxABC%2FLBXNetwork/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/MxABC%2FLBXNetwork/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/MxABC","download_url":"https://codeload.github.com/MxABC/LBXNetwork/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248208565,"owners_count":21065202,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T04:42:19.069Z","updated_at":"2025-04-10T11:13:00.489Z","avatar_url":"https://github.com/MxABC.png","language":"Objective-C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# LBXNetWork\n\n#### 项目介绍\n轻量级http请求，基于封装AFN3.x + YYCache，\n接口设计上，通过block返回创建好的请求模型对象，调用者只有对非默认值属性进行修改即可，接口调用完成也只通过一个block来回调，具体情况通过响应模型对象来解析，请求参数及结果都通过一个对象来完成，方便扩展，具体使用时，可结合自己的app，增加一层业务层接口，业务层内部添加hud，默认参数，安全策略等\n\n- 支持GET、POST、PUT、DELETE\n- 支持批量请求 \n- 支持缓存\n\n#### install by cocoapods\n\n需要AFNetworking4.0和YYCache1.x支持\n\n```\npod 'LBXNetWork', '~\u003e 1.0.1'\n```\n\n#### 手动\n将LBXNetWork文件夹拖到工程里，并且需要AFNetworking4.x和YYCache1.0.x库\n\n#### 使用示例\n具体使用看Demo首页里面几个调用方法以及模拟业务层`LBXNetwork (TheAPP)`代码及说明\n\n```\n [LBXNetwork HttpWithRequestBlock:^(LBXHttpRequest * request) {\n        \n       request.responseSerializerType = LBXHTTPSerializerTypeRAW;\n       request.httpMethod = LBXHTTPMethodTypeGET;\n       request.responseAcceptableContentTypes = [NSSet setWithObjects:@\"text/html\",@\"application/javascript\",nil];\n       \n       request.server = @\"https://tcc.taobao.com/\";\n       request.api = @\"cc/json/mobile_tel_segment.htm\";\n       //        request.requestUrl = @\"https://tcc.taobao.com/cc/json/mobile_tel_segment.htm\";\n       \n       \n        request.requestParameters = @{@\"tel\":@\"15852509988\"};\n        \n    } complection:^(LBXHttpResponse * _Nonnull response) {\n        NSLog(@\"response\");\n        \n        if (response.success \u0026\u0026 response.responseObject) {\n            \n            NSString *str = [[NSString alloc]initWithData:response.responseObject encoding:NSASCIIStringEncoding];\n            \n            NSLog(@\"%@\",str);\n        }\n        else if (response.error)\n        {\n            NSLog(@\"error:%@\",response.error);\n            //用户主动取消请求\n            if (response.error.code == NSURLErrorCancelled) {\n                NSLog(@\"user canceled\");\n            }\n        }\n    }];\n```\n\nLBXHttpRequest请求参数通过block回调回来，调用者根据主要根据接口实际业务填充相关参数即可\n下面为LBXHttpRequest的定义，具体使用时，查看每个属性的说明即可\n\n```\n///请求或返回数据形式\ntypedef NS_ENUM(NSInteger, LBXHTTPSerializerType) {\n    LBXHTTPSerializerTypeJSON = 0,      /// JSON object\n    LBXHTTPSerializerTypeRAW = 1 //NSData object,二进制数据,内部已经默认设置 Content-Type  application/x-www-form-urlencoded\n};\n\n/**\n HTTP methods 请求方法.\n */\ntypedef NS_ENUM(NSInteger, LBXHTTPMethodType) {\n    LBXHTTPMethodTypeGET    = 0,\n    LBXHTTPMethodTypePOST   = 1,\n    LBXHTTPMethodTypeDELETE = 2,\n    LBXHTTPMethodTypePUT    = 3\n};\n\n\n@interface LBXHttpRequest : AFNNetworkRequest\n\n/**\n The server address for request, eg. \"http://example.com/v1/\"\n */\n@property (nonatomic, copy, nullable) NSString *server;\n\n/**\n The API interface path for request, eg. \"foo/bar\", `nil` by default.\n */\n@property (nonatomic, copy, nullable) NSString *api;\n\n/**\n The final URL of request, which is combined by `server` and `api` properties, eg. \"http://example.com/v1/foo/bar\", `nil` by default.\n NOTE: when you manually set the value for `requestUrl`, the `server` and `api` properties will be ignored.\n */\n@property (nonatomic, copy, nullable) NSString *requestUrl;\n\n///上传参数形式，默认值 LBXHTTPSerializerTypeJSON\n@property (nonatomic, assign) LBXHTTPSerializerType requestSerializerType;\n\n///返回数据类型,默认值 LBXHTTPSerializerTypeJSON\n@property (nonatomic, assign) LBXHTTPSerializerType responseSerializerType;\n\n//请求方法,GET,POST,DELETE,PUT，默认POST\n@property (nonatomic, assign) LBXHTTPMethodType httpMethod;\n\n///请求超时时间,默认10s\n@property (nonatomic, assign) NSTimeInterval timeoutInterval;\n\n///设置http请求信息头(HTTPHeaderField)，默认为nil\n@property (nonatomic, strong,nullable) NSDictionary\u003cNSString*,NSString*\u003e *headers;\n\n///上传参数，类型为NSDictionary或NSData,默认nil\n@property (nonatomic, strong,nullable) id requestParameters;\n\n/**\n 接收http响应数据ContentTypes\n 默认值:\n [NSSet setWithObjects:@\"application/json\",@\"text/json\",@\"text/javascript\",@\"application/javascript\",@\"text/html\",@\"text/plain\",@\"multipart/form-data\",nil];\n */\n@property (nonatomic, copy, nullable) NSSet \u003cNSString *\u003e *responseAcceptableContentTypes;\n\n/**\n 如果设置YES，在requestParameters赋值的时候，会打印请求数据的日志\n 默认值策略：\n - debug环境：YES\n - release环境：NO\n */\n@property (nonatomic) BOOL debugLogEnabled;\n\n/**\n 支持缓存，调用成功后缓存到本地，调用失败，读取缓存,默认值NO\n */\n@property (nonatomic, assign) BOOL cacheEnable;\n\n/**\n 先读取缓存，不调用接口，如果没有缓存则调用接口，默认值NO\n */\n@property (nonatomic, assign) BOOL cachedPrior;\n\n\n/**\n 报错统一处理，供上层使用，LBXNetwork没有使用该参数\n 默认值NO\n \n 如业务层可以添加一层，报错自动弹出toast提示错误,\n 如果有报错信息，且errAutoHandle为YES，则响应返回needHandle值为NO\n */\n@property (nonatomic, assign) BOOL errAutoHandle;\n\n@end\n```\n\n接口返回模型定义\n\n```\n@interface LBXHttpResponse : NSObject\n\n/**\n LBXNetwork层没有使用该参数，上层封装时可以参考以下建议使用\n \n - 上层是否需要处理，部分业务可能底层统一处理了，如用户取消请求，业务上统一报错的toast提示等\n - 接口返回返回的地方，先判断值是否为YES，为NO一般不需要处理，其他情况：如果是下拉刷新则结束下拉刷新即可\n - 如果业务上不需要该参数，也可以忽略参数\n */\n@property (nonatomic, assign,getter=isNeedHandle) BOOL needHandle;\n\n/**\n 接口是否调用成功,下面2种情况下值为YES\n - 接口调用成功，不是网络连接失败\n - 网络连接失败，但是读取缓存数据成功，cachedResponse设置为YES\n */\n@property (nonatomic, assign) BOOL success;\n\n///接口返回失败后的错误信息，如果成功则为nil,有错误信息，responseObject数据也可能读取了缓存的数据\n@property (nonatomic, strong,nullable) NSError *error;\n\n///保存的请求信息\n@property (nonatomic, strong,nullable) LBXHttpRequest *request;\n\n/**\n 如果设置YES，在responseObject赋值的时候，会打印返回的数据的日志\n 默认值策略：\n - debug环境：YES\n - release环境：NO\n */\n@property (nonatomic) BOOL debugLogEnabled;\n\n/**\n 调用成功后的返回数据，接口返回或读取缓存的数据，类型为NSDictionary或NSData\n */\n@property (nonatomic, strong,nullable) id responseObject;\n\n///返回的数据是否是缓存的\n@property (nonatomic, assign,getter=isCachedResponse) BOOL cachedResponse;\n\n///返回参数，初始化默认值-1,成功请求后的值为http statuscode的值,如200,301,404,500等\n\n/**\n http statusCode\n 默认值为-1\n 接口调用成功后，一般值为2xx,3xx,4xx,5xx\n */\n@property (nonatomic, assign) NSInteger statusCode;\n\n@end\n\n```\n\n#### 参考\n- **[XMNetworking](https://github.com/kangzubin/XMNetworking)**\n- **[PPNetworkHelper](https://github.com/jkpang/PPNetworkHelper)** \n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxabc%2Flbxnetwork","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmxabc%2Flbxnetwork","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmxabc%2Flbxnetwork/lists"}