Inherits from NSObject
Declared in http_request.h

Overview

http_request is an iOS light-weight library that simplifies asynchronous HTTP operations.

Tasks

Properties

bodyParser

The body parser block property.

@property (copy) id ( ^ ) ( NSURLResponse *, NSData *, NSError *__autoreleasing *) bodyParser

Declared In

http_request.h

bodySerializer

The body serializer block property.

@property (copy) NSData *^ ) ( id , NSError *__autoreleasing *) bodySerializer

Declared In

http_request.h

responseValidator

The response validator block property.

@property (copy) BOOL ( ^ ) ( NSURLResponse *, id body , NSError *__autoreleasing *) responseValidator

Declared In

http_request.h

Class Methods

constructRequest:withUrl:withHeaders:withBody:

Constructs an HTTP request given the provided parameters.

+ (NSMutableURLRequest *)constructRequest:(NSString *)method withUrl:(NSURL *)url withHeaders:(NSDictionary *)headers withBody:(NSData *)data

Parameters

method

The HTTP method (e.g. @“GET”, @“PUT”, @“POST, @"PATCH”, @“DELETE”, …). Must not be nil.

url

The uniform resource locator to retrieve the content from. Must not be nil.

headers

The HTTP headers to provide as part of the request. Optional, can be nil.

data

The data to use in the body of the request. Optional, can be nil.

Return Value

The constructed HTTP request.

Declared In

http_request.h

isClientErrorStatusCode:

Determines whether or not the status code is a client error.

+ (BOOL)isClientErrorStatusCode:(int)statusCode

Parameters

statusCode

The HTTP status code.

Return Value

YES if it is a client error; otherwise, NO.

Declared In

http_request.h

isInformationalStatusCode:

Determines whether or not the status code is informational.

+ (BOOL)isInformationalStatusCode:(int)statusCode

Parameters

statusCode

The HTTP status code.

Return Value

YES if it is informational; otherwise, NO.

Declared In

http_request.h

isRedirectionStatusCode:

Determines whether or not the status code is redirection.

+ (BOOL)isRedirectionStatusCode:(int)statusCode

Parameters

statusCode

The HTTP status code.

Return Value

YES if it is redirection; otherwise, NO.

Declared In

http_request.h

isServerErrorStatusCode:

Determines whether or not the status code is a server error.

+ (BOOL)isServerErrorStatusCode:(int)statusCode

Parameters

statusCode

The HTTP status code.

Return Value

YES if it is a server error; otherwise, NO.

Declared In

http_request.h

isSuccessStatusCode:

Determines whether or not the status code is successful.

+ (BOOL)isSuccessStatusCode:(int)statusCode

Parameters

statusCode

The HTTP status code.

Return Value

YES if it is successful; otherwise, NO.

Declared In

http_request.h

isValidResponse:withBody:error:

Validates the HTTP response of a request.

+ (BOOL)isValidResponse:(NSURLResponse *)response withBody:(id)body error:(NSError *__autoreleasing *)error

Parameters

response

The response to validate. Must not be nil.

body

The response body. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

Determines whether there was a reponse error or not.

Declared In

http_request.h

jsonDataParser:error:

Converts the provided NSData into its JSON representation.

+ (id)jsonDataParser:(NSData *)data error:(NSError *__autoreleasing *)error

Parameters

data

The data to parse. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The NSDictionary representing the parsed data.

Declared In

http_request.h

parseBody:withBody:error:

Parses the data given a response.

+ (id)parseBody:(NSURLResponse *)response withBody:(NSData *)data error:(NSError *__autoreleasing *)error

Parameters

response

The response. Must not be nil.

data

The data to parse as the body. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The parsed body in its corresponding representation.

Declared In

http_request.h

serializeBody:error:

Serializes the body for a request.

+ (NSData *)serializeBody:(id)body error:(NSError *__autoreleasing *)error

Parameters

body

The data to serialize as the body. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The serialized body in its corresponding representation.

Declared In

http_request.h

serializeJson:error:

Converts the provided JSON into its NSData representation.

+ (NSData *)serializeJson:(NSDictionary *)dict error:(NSError *__autoreleasing *)error

Parameters

dict

The JSON to serialize. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The NSData representing the serialized JSON.

Declared In

http_request.h

serializeString:error:

Converts the provided String into its NSData representation.

+ (NSData *)serializeString:(NSString *)str error:(NSError *__autoreleasing *)error

Parameters

str

The String to serialize. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The NSData representing the serialized String.

Declared In

http_request.h

stringDataParser:error:

Converts the provided NSData into its String representation.

+ (id)stringDataParser:(NSData *)data error:(NSError *__autoreleasing *)error

Parameters

data

The data to parse. Optional, can be nil.

error

The error, if any. Must not be nil.

Return Value

The NSString representing the parsed data.

Declared In

http_request.h

Instance Methods

deleteAsync:onSuccess:onError:

Removes the content for the provided url.

- (NSURLSessionDataTask *)deleteAsync:(NSURL *)url onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to retrieve the content from. Must not be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

deleteAsync:withHeaders:onSuccess:onError:

Removes the content for the provided url.

- (NSURLSessionDataTask *)deleteAsync:(NSURL *)url withHeaders:(NSDictionary *)headers onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to retrieve the content from. Must not be nil.

headers

The HTTP headers to provide as part of the request. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

getAsync:onSuccess:onError:

Get the content for the provided url.

- (NSURLSessionDataTask *)getAsync:(NSURL *)url onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to retrieve the content from. Must not be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

getAsync:withHeaders:onSuccess:onError:

Get the content for the provided url.

- (NSURLSessionDataTask *)getAsync:(NSURL *)url withHeaders:(NSDictionary *)headers onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to retrieve the content from. Must not be nil.

headers

The HTTP headers to provide as part of the request. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

init

The default instance initializer.

- (id)init

Return Value

An instance of class.

Declared In

http_request.h

initWithConfiguration:

Initializes the instance with a provided configuration.

- (id)initWithConfiguration:(NSURLSessionConfiguration *)sessionConfiguration

Parameters

sessionConfiguration

The session configuration used to initialize the instance.

Return Value

An instance of class.

Declared In

http_request.h

issueAsync:onSuccess:onError:

Issues an HTTP request, parses the response body and validates the status code.

- (NSURLSessionDataTask *)issueAsync:(NSMutableURLRequest *)request onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

request

The HTTP request to issue. Must not be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

issueAsync:withBodyParser:withResponseValidation:onSuccess:onError:

Issues an HTTP request, parses the response body and validates the status code.

- (NSURLSessionDataTask *)issueAsync:(NSMutableURLRequest *)request withBodyParser:(id ( ^ ) ( NSURLResponse *, NSData *, NSError *__autoreleasing *))bodyParser withResponseValidation:(BOOL ( ^ ) ( NSURLResponse *, id , NSError *__autoreleasing *))validateResponse onSuccess:(void ( ^ ) ( NSURLResponse *, id ))successCallback onError:(void ( ^ ) ( NSError *))errorCallback

Parameters

request

The HTTP request to issue. Must not be nil.

bodyParser

The parser used to convert the body. Optional, can be nil.

validateResponse

The validator used to check the response. Optional, can be nil.

successCallback

The callback called upon success; passes the response and the body. Must not be nil.

errorCallback

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withBody:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

data

The NSData to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withHeaders:withBody:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

data

The NSData to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withHeaders:withJson:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

dict

The NSDictionary to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withHeaders:withString:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

str

The NSString to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withJson:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

dict

The NSDictionary to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

patchAsync:withString:onSuccess:onError:

Patch the content for the provided url.

- (NSURLSessionDataTask *)patchAsync:(NSURL *)url withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

str

The NSString to be used as the body of the request and with which to patch the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withBody:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

data

The NSData to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withHeaders:withBody:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

data

The NSData to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withHeaders:withJson:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

dict

The NSDictionary to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withHeaders:withString:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

str

The NSString to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withJson:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

dict

The NSDictionary to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

postAsync:withString:onSuccess:onError:

Post the content for the provided url.

- (NSURLSessionDataTask *)postAsync:(NSURL *)url withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

str

The NSString to be used as the body of the request and with which to post the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withBody:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

data

The NSData to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withHeaders:withBody:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withBody:(NSData *)data onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

data

The NSData to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withHeaders:withJson:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

dict

The NSDictionary to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withHeaders:withString:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withHeaders:(NSDictionary *)headers withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

headers

The NSDitionary representing the headers to set for the request. Optional, can be nil.

str

The NSString to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withJson:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withJson:(NSDictionary *)dict onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

dict

The NSDictionary to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h

putAsync:withString:onSuccess:onError:

Put the content for the provided url.

- (NSURLSessionDataTask *)putAsync:(NSURL *)url withString:(NSString *)str onSuccess:(void ( ^ ) ( NSURLResponse *, id ))success onError:(void ( ^ ) ( NSError *))error

Parameters

url

The uniform resource locator to update the content with. Must not be nil.

str

The NSString to be used as the body of the request and with which to put the url with. Optional, can be nil.

success

The callback called upon success; passes the response and the body. Must not be nil.

error

The callback called upon error; passes an NSError. Must not be nil.

Return Value

The task representing the operation.

Declared In

http_request.h