A lite api framework that implemented basic RPC reqirements. We use chaining coding style to provide convenience of calling methods. We have covered most situations of http/https request between iOS client and your backend.
- Store a template, import it and modify very few of params before you call an http request.
- Most of an http request's params can be modified at one method. It's convenient and short.
- Two life cycle callbacks for every request,
willStart
anddidFinish
. - Make your callbacks dispatching to current/main/background thread by setting a flag.
- Hot-time API environment exchanging.
- File transformation support.
- JSON/XML/... to model support.
- More...
pod "LiteAPI"
- (void)createYourAPITemplate {
[LA createTemplate:^(LARequestMaker *maker) {
maker.host(@"http://your-host").version(@"v1").method(LAMethodGET);
maker.post(LAPostStyleForm).sync(NO).response(LAResponseStyleJSON);
maker.willStart.delegate(self, @selector(sign:));
}
withIdentifier:@"template"
onStatus:LAStatusProduction];
}
- (NSURLRequest *)sign:(NSMutableURLRequest *)request {
//do your sign
return request;
}
- (void)invokeYourAPI {
[LA invokeRequest:^(LARequestMaker *maker) {
maker.import(@"template").path(@"/ping");
maker.didFinish.thread(LAThreadBackground).block(^id(LAResponse *response){
NSLog(@"%@", response.JSON);
return nil;
});
}];
}
or you may not want to use block:
- (void)invokeYourAPI {
[LA invokeRequest:^(LARequestMaker *maker) {
maker.import(@"template").path(@"/ping");
maker.didFinish.thread(LAThreadBackground).delegate(self, @selector(didFinish:));
}];
}
- (id)didFinish:(LAResponse *)response {
//do your business
return nil;
}
- (void)example {
[LA createTemplate:^(LARequestMaker *maker) {
maker.import(@"template").host(@"http://your-beta-host");
}
withIdentifier:@"template"
onStatus:LAStatusBeta];
[LA switchStatusTo:LAStatusBeta];
}