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

Configuring a Request

Reading the Response

Creating a Request

Initializing a Request

Loading a Request

Properties

body

HTTP body data.

@property (nonatomic, copy) NSData *body

Discussion

HTTP body data.

Declared In

YYHRequest.h

completeOnMainThread

Determines if the success and failure callbacks are called on the main thread. Default to YES.

@property (nonatomic, assign, getter=shouldCompleteOnMainThread) BOOL completeOnMainThread

Discussion

Determines if the success and failure callbacks are called on the main thread. Default to YES.

Declared In

YYHRequest.h

contentType

User agent string.

@property (nonatomic, copy) NSString *contentType

Discussion

User agent string.

Declared In

YYHRequest.h

headers

Request headers.

@property (nonatomic, copy) NSMutableDictionary *headers

Discussion

Request headers.

Declared In

YYHRequest.h

method

NSURL used to load the request.

@property (nonatomic, copy) NSString *method

Discussion

NSURL used to load the request.

Declared In

YYHRequest.h

parameters

Request parameters.

@property (nonatomic, copy) NSMutableDictionary *parameters

Discussion

Request parameters.

Declared In

YYHRequest.h

requestQueue

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 *requestQueue

Discussion

Set to specify the NSOperationQueue instance used for queueing connection operations. If unspecified a shared request queue is created as sharedRequestQueue.

Declared In

YYHRequest.h

response

NSURLResponse object representing the state of the received response.

@property (nonatomic, readonly, copy) NSURLResponse *response

Discussion

NSURLResponse object representing the state of the received response.

Declared In

YYHRequest.h

url

NSURL used to load the request.

@property (nonatomic, copy) NSURL *url

Discussion

NSURL used to load the request.

Declared In

YYHRequest.h

userAgent

User agent string.

@property (nonatomic, copy) NSString *userAgent

Discussion

User agent string.

Declared In

YYHRequest.h

Class Methods

loadRequestWithURL:success:failure:

Create and load a request.

+ (instancetype)loadRequestWithURL:(NSURL *)url success:(void ( ^ ) ( NSData *data ))success failure:(void ( ^ ) ( NSError *error ))failure

Parameters

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

requestWithURL:

Create request.

+ (instancetype)requestWithURL:(NSURL *)url

Parameters

url

NSURL used to load the request.

success

Called when request has loaded successfully.

failure

Called when request fails to load.

Discussion

Create request.

Declared In

YYHRequest.h

sharedRequestQueue

Access the shared request queue instance.

+ (NSOperationQueue *)sharedRequestQueue

Discussion

Access the shared request queue instance.

Declared In

YYHRequest.h

Instance Methods

initWithURL:

Initialize request.

- (instancetype)initWithURL:(NSURL *)url

Parameters

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

loadRequest

Create connection and load request.

- (void)loadRequest

Discussion

Create connection and load request.

Declared In

YYHRequest.h

loadRequestWithSuccess:failure:

Create connection and load the request.

- (void)loadRequestWithSuccess:(void ( ^ ) ( NSData *data ))success failure:(void ( ^ ) ( NSError *error ))failure

Parameters

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

onFailure:

Set callback block to be invoked when the request fails.

- (void)onFailure:(void ( ^ ) ( NSError *error ))failure

Discussion

Set callback block to be invoked when the request fails.

Declared In

YYHRequest.h

onSuccess:

Set callback block to be invoked when the request has loaded successfully.

- (void)onSuccess:(void ( ^ ) ( NSData *data ))success

Discussion

Set callback block to be invoked when the request has loaded successfully.

Declared In

YYHRequest.h