TestsTested | ✓ |
LangLanguage | Obj-CObjective C |
License | MIT |
ReleasedLast Release | Sep 2015 |
LupinusHTTP is an HTTP networking library, wrapping NSURLSession
.
LupinusHTTP has very simple step to request.
LupinusHTTPRequest
through LupinusHTTP
's method.
responseJSON
or responseString
methods.Example: Get Request to http://httpbin.org/get?key=value
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get" query:@{
@"key" : @"value"
}];
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
NSLog(@"JSON = %@", JSON);
}];
Always response*
complete method involked in matin thread.
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get"];
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
NSLog(@"JSON = %@", JSON);// => JSON Object(NSDictionary or NSArray)
}];
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get"];
[httpRequest responseString:^(NSURLRequest *request, NSURLResponse *response, NSString *string, NSError *error) {
NSLog(@"string = %@", string);// => NSString
}];
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get"];
[httpRequest responseRawData:^(NSURLRequest *request, NSURLResponse *response, NSData *data, NSError *error) {
// data
}];
e.g) http://httpbin.org/post?key=value
body
[1,2,3]
[LupinusHTTP request:LupinusMethodPOST URL:@"http://httpbin.org/post" query:@{
@"key" : @"value"
} body:@[@1, @2, @3]];
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
NSLog(@"JSON = %@", JSON);// => JSON Object(NSDictionary or NSArray)
}];
When response.statusCode >= 400, recognize request as failed and error
is filled by status code of.
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/status/403"];
// response status code is 403
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
// error is not nil
if(error){
NSLog(@"%@", error);
}
}];
You can create a new session with a modified session configuration.
// default : [NSURLSessionConfiguration defaultSessionConfiguration]
+ (instancetype)httpWithSessionConfiguration:(NSURLSessionConfiguration *) sessionConfiguration;
You can cancel the request by LupinusHTTPRequest#cancel
.
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get"];
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
// this callback doens't call!
}];
// cancel request
[httpRequest cancel];
Request flow design of LupinusHTTP.
// Create NSURLSession and NSURLRequest.
LupinusHTTPRequest *httpRequest = [LupinusHTTP request:LupinusMethodGET URL:@"http://httpbin.org/get"];
// already started HTTP request
// ...
// you can register complete handler
// Lupinus add this handler to `queue`
[httpRequest responseJSON:^(NSURLRequest *request, NSURLResponse *response, id JSON, NSError *error) {
NSLog(@"JSON = %@", JSON);// => JSON Object(NSDictionary or NSArray)
}];
// ....
// Get HTTP response.
// Lupinus dispatch_resume(self.queue); => callback the complete handlers.
No.
LupinusHTTP doens't work with Background Fetch.
NSURLSessionDownloadTask
.But, welcome to your pull request!
git checkout -b my-new-feature
git commit -am 'Add some feature'
git push origin my-new-feature
LupinusHTTP is available under the MIT license. See the LICENSE file for more info.
LupinusHTTP inspired by Alamofire, AFNetworking and TacoShell.
Photo by Tatu Väyrynen