An iOS Objective-C light-weight library that simplifies asynchronous HTTP operations.
- Clone repo:
git clone https://github.com/langholz/http-request.git
- Open workspace, select the
httprequestlib
target and build (which generates a static library). - Follow Apple's documentation on how to use static libraries in iOS
With http-request
you are able to perform simple HTTP operations in a light-weight manner.
http_request *httpRequest = [http_request new];
NSURLSessionDataTask *task = [httpRequest
getAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
getAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
posAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withBody:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withJson:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withString:body
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
deleteAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
NSURLSessionDataTask *task = [httpRequest
deleteAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
[http_request
constructRequest:@"GET"
withUrl:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withBody:body];
NSURLSessionDataTask *task = [httpRequest
issueAsync:request
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
[http_request
constructRequest:@"GET"
withUrl:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
withBody:body];
NSURLSessionDataTask *task = [httpRequest
issueAsync:request
withBodyParser:nil
withResponseValidation:nil
onSuccess:^(NSURLResponse *response, id body)
{
// Success
}
onError:^(NSError *error)
{
// Error
}];
- Relies on the OHHTTPStubs CocoaPod and XCTest.
- Make sure you have the CocoaPod dependencies.
- Install by changing to the directory and running
pod install
. - Run tests in Xcode.
- HTML documentation
- The project includes a
Documentation
target which generates, through appledoc, thedocs
directory containing the corresponding documentation.