Git Product home page Git Product logo

lfrequest's Introduction

LFRequest

CI Status Version License Platform

示例

Example工程中有使用示例,可以下载后 pod install试运行,查看简单使用。

安装

LFRequest 可以从 CocoaPods上获取。 在Podfile上添加pod 'LFRequest',然后pod install即可。

pod 'LFRequest'

使用教程

一、公共部分设置

#import <LFRequest/LFNetworkManager.h>

LFNetworkConfig *config = [LFNetworkConfig new];
// 域名配置
config.domainBlock = ^NSString * _Nonnull{
    return @"http://mock.studyinghome.com/mock/5eaa69714006b044ae246153/request";
};
// 请求头设置
config.commonHeaderBlock = ^NSDictionary * _Nonnull{
		return @{
        @"commonHeader":@"commonHeader",
        @"userToken":@"xxxxxxxxxxxxxxxxxxx",
    };
};
// 数据解析设置,LFCommonDataParse遵守LFDataParseDelegate协议
config.commonDataParse = [LFCommonDataParse new];
// 设置到manager上
[LFNetworkManager manager].config = config;

二、LFRequest创建

+ (instancetype)GetWithDomain:(nullable NSString *)domain
                          uri:(NSString *)uri
                     rspClass:(nullable Class)rspClass
                    needCache:(BOOL)needCache;

+ (instancetype)GetWithUri:(NSString *)uri
                  rspClass:(nullable Class)rspClass
                 needCache:(BOOL)needCache;

+ (instancetype)GetWithUri:(NSString *)uri
                  rspClass:(nullable Class)rspClass;

+ (instancetype)PostWithDomain:(nullable NSString *)domain
                           uri:(NSString *)uri
                      rspClass:(nullable Class)rspClass;

+ (instancetype)PostWithUri:(NSString *)uri
                   rspClass:(nullable Class)rspClass;

// 例如
- (LFRequest *)homeRequest {
    if (!_homeRequest) {
        _homeRequest = [LFRequest PostWithUri:@"/home" rspClass:LFHomeInfo.class];
        _homeRequest.dataParse = self;	// 可以自定义接口的数据解析
        _homeRequest.serializerType = LFRequestSerializerTypeJson;	// 请求序列化,默认为http
        _homeRequest.requestTimeout = 10;	// 设置超时时间
    }
    return _homeRequest;
}

三、请求

#pragma mark < 主线程返回数据 >
- (void)requestSuccess:(nullable LFNetSuccBlock)success
               failure:(nullable LFNetFailBlock)failure;

- (void)requestParams:(nullable NSDictionary *)params
              success:(nullable LFNetSuccBlock)success
              failure:(nullable LFNetFailBlock)failure;

- (void)requestParams:(nullable NSDictionary *)params
               header:(nullable NSDictionary *)header
              success:(nullable LFNetSuccBlock)success
              failure:(nullable LFNetFailBlock)failure;

#pragma mark < 异步返回数据 >
- (void)requestAsynBackSuccess:(nullable LFNetSuccBlock)success
                       failure:(nullable LFNetFailBlock)failure;

- (void)requestAsynBackParams:(nullable NSDictionary *)params
                      success:(nullable LFNetSuccBlock)success
                      failure:(nullable LFNetFailBlock)failure;

- (void)requestAsynBackParams:(nullable NSDictionary *)params
                       header:(nullable NSDictionary *)header
                      success:(nullable LFNetSuccBlock)success
                      failure:(nullable LFNetFailBlock)failure;

// 例如
[self.presenter.homeRequest requestParams:@{
     @"userId":@"1233455",
} header:@{
     @"selfHeader":@"www.feiyu.com"
} success:^(id rspModel, NSDictionary *rspJson) {
     
} failure:^(NSError *error) {
  	
}];

Author

feiyu [email protected]

License

LFRequest is available under the MIT license. See the LICENSE file for more info.

lfrequest's People

Contributors

vvlongfei avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.