YYHRequest Class Reference
| Inherits from | NSObject |
| Conforms to | NSURLConnectionDataDelegate |
| Declared in | YYHRequest.h YYHRequest.m |
Overview
Simple and lightweight class for loading asynchronous HTTP requests. Built on NSURLConnection and NSOperationQueue.
Usage
Create and load a request
NSURL *url = [NSURL URLWithString:@"http://foo.bar"];
[YYHRequest loadRequestWithURL:url success:^(NSData *data) {
} failure:^(NSError *error) {
}];
Create request and load manually.
YYHRequest *request = [YYHRequest requestWithURL:url];
[request onSuccess:^(NSData *data) {
// request complete
}];
[request loadRequest];
Tasks
Getting the Shared Request Operation Queue
Specifying the Request Operation Queue
-
requestQueueproperty
Configuring a Request
-
urlproperty -
methodproperty -
bodyproperty -
userAgentproperty -
contentTypeproperty -
headersproperty -
parametersproperty -
completeOnMainThreadproperty -
– onSuccess: -
– onFailure:
Reading the Response
-
responseproperty
Creating a Request
Initializing a Request
Loading a Request
Properties
body
HTTP body data.
@property (nonatomic, copy) NSData *bodyDiscussion
HTTP body data.
Declared In
YYHRequest.hcompleteOnMainThread
Determines if the success and failure callbacks are called on the main thread. Default to YES.
@property (nonatomic, assign, getter=shouldCompleteOnMainThread) BOOL completeOnMainThreadDiscussion
Determines if the success and failure callbacks are called on the main thread. Default to YES.
Declared In
YYHRequest.hcontentType
User agent string.
@property (nonatomic, copy) NSString *contentTypeDiscussion
User agent string.
Declared In
YYHRequest.hheaders
Request headers.
@property (nonatomic, copy) NSMutableDictionary *headersDiscussion
Request headers.
Declared In
YYHRequest.hmethod
NSURL used to load the request.
@property (nonatomic, copy) NSString *methodDiscussion
NSURL used to load the request.
Declared In
YYHRequest.hparameters
Request parameters.
@property (nonatomic, copy) NSMutableDictionary *parametersDiscussion
Request parameters.
Declared In
YYHRequest.hrequestQueue
Set to specify the NSOperationQueue instance used for queueing connection operations. If unspecified a shared request queue is created as sharedRequestQueue.
@property (nonatomic, strong) NSOperationQueue *requestQueueDiscussion
Set to specify the NSOperationQueue instance used for queueing connection operations. If unspecified a shared request queue is created as sharedRequestQueue.
Declared In
YYHRequest.hresponse
NSURLResponse object representing the state of the received response.
@property (nonatomic, readonly, copy) NSURLResponse *responseDiscussion
NSURLResponse object representing the state of the received response.
Declared In
YYHRequest.hClass Methods
loadRequestWithURL:success:failure:
Create and load a request.
+ (instancetype)loadRequestWithURL:(NSURL *)url success:(void ( ^ ) ( NSData *data ))success failure:(void ( ^ ) ( NSError *error ))failureParameters
- url
NSURL used to load the request.
- success
Called when request has loaded successfully.
- failure
Called when request fails to load.
Discussion
Create and load a request.
Declared In
YYHRequest.hInstance Methods
initWithURL:
Initialize request.
- (instancetype)initWithURL:(NSURL *)urlParameters
- url
NSURL used to load the request.
- success
Called when request has loaded successfully.
- failure
Called when request fails to load.
Discussion
Initialize request.
Declared In
YYHRequest.hloadRequest
Create connection and load request.
- (void)loadRequestDiscussion
Create connection and load request.
Declared In
YYHRequest.hloadRequestWithSuccess:failure:
Create connection and load the request.
- (void)loadRequestWithSuccess:(void ( ^ ) ( NSData *data ))success failure:(void ( ^ ) ( NSError *error ))failureParameters
- success
Called when request has loaded successfully.
- failure
Called when request fails to load.
Discussion
Create connection and load the request.
Declared In
YYHRequest.h