Skip to content
This repository was archived by the owner on Apr 1, 2020. It is now read-only.
/ http-request Public archive

Objective-C iOS light-weight library that simplifies asynchronous HTTP operations.

License

Notifications You must be signed in to change notification settings

langholz/http-request

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

http-request

An iOS Objective-C light-weight library that simplifies asynchronous HTTP operations.

Install

Usage

With http-request you are able to perform simple HTTP operations in a light-weight manner.

Create and initialize instance

http_request *httpRequest = [http_request new];

GET request

 NSURLSessionDataTask *task = [httpRequest
                               getAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

GET request with headers

 NSURLSessionDataTask *task = [httpRequest
                               getAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PUT request with NSData as the request body

 NSURLSessionDataTask *task = [httpRequest
                               putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withBody:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PUT request with NSDictionary as the request body

 NSURLSessionDataTask *task = [httpRequest
                               putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withJson:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PUT request with NSString as the request body

 NSURLSessionDataTask *task = [httpRequest
                               putAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withString:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PUT request with headers and NSData as the request body

 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
                               }];

PUT request with headers and NSDictionary as the request body

 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
                               }];

PUT request with headers and NSString as the request body

 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
                               }];

POST request with NSData as the request body

 NSURLSessionDataTask *task = [httpRequest
                               postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withBody:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

POST request with NSDictionary as the request body

 NSURLSessionDataTask *task = [httpRequest
                               postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withJson:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

POST request with NSString as the request body

 NSURLSessionDataTask *task = [httpRequest
                               postAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withString:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

POST request with headers and NSData as the request body

 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
                               }];

POST request with headers and NSDictionary as the request body

 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
                               }];

POST request with headers and NSString as the request body

 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
                               }];

PATCH request with NSData as the request body

 NSURLSessionDataTask *task = [httpRequest
                               patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withBody:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PATCH request with NSDictionary as the request body

 NSURLSessionDataTask *task = [httpRequest
                               patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withJson:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PATCH request with NSString as the request body

 NSURLSessionDataTask *task = [httpRequest
                               patchAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withString:body
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

PATCH request with headers and NSData as the request body

 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
                               }];

PATCH request with headers and NSDictionary as the request body

 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
                               }];

PATCH request with headers and NSString as the request body

 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
                               }];

DELETE request

 NSURLSessionDataTask *task = [httpRequest
                               deleteAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

DELETE request with headers

 NSURLSessionDataTask *task = [httpRequest
                               deleteAsync:[[NSURL alloc] initWithString:@"http://www.langholz.net"]
                               withHeaders:@{@"MyHeaderName":@"MyHeaderValue"}
                               onSuccess:^(NSURLResponse *response, id body)
                               {
                                    // Success
                               }
                               onError:^(NSError *error)
                               {
                                   // Error
                               }];

ISSUE verb request with automated parsing and status code validation

 [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
                               }];

ISSUE verb request with optional parsing and optional status code validation

 [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
                               }];

Tests

  • 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.

Documentation

  • HTML documentation
  • The project includes a Documentation target which generates, through appledoc, the docs directory containing the corresponding documentation.

About

Objective-C iOS light-weight library that simplifies asynchronous HTTP operations.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published