Documentation for AFHTTPClient and AFHTTPClientOperation protocol
This commit is contained in:
parent
340fbf19eb
commit
49d5c65687
1 changed files with 50 additions and 13 deletions
|
|
@ -26,6 +26,9 @@
|
||||||
@protocol AFHTTPClientOperation;
|
@protocol AFHTTPClientOperation;
|
||||||
@protocol AFMultipartFormData;
|
@protocol AFMultipartFormData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Method used to encode parameters into request body
|
||||||
|
*/
|
||||||
typedef enum {
|
typedef enum {
|
||||||
AFFormURLParameterEncoding,
|
AFFormURLParameterEncoding,
|
||||||
AFJSONParameterEncoding,
|
AFJSONParameterEncoding,
|
||||||
|
|
@ -33,9 +36,23 @@ typedef enum {
|
||||||
} AFHTTPClientParameterEncoding;
|
} AFHTTPClientParameterEncoding;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
`AFHTTPClient` objects encapsulates the common patterns of communicating with an application, webservice, or API. It encapsulates persistent information, like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations.
|
`AFHTTPClient` captures the common patterns of communicating with an web application over HTTP. It encapsulates information like base URL, authorization credentials, and HTTP headers, and uses them to construct and manage the execution of HTTP request operations.
|
||||||
|
|
||||||
In its default implementation, `AFHTTPClient` sets the following HTTP headers:
|
## Automatic Content Parsing
|
||||||
|
|
||||||
|
Instances of `AFHTTPClient` may specify which types of requests it expects and should handle by registering HTTP operation classes for automatic parsing. Registered classes will determine whether they can handle a particular request, and then construct a request operation accordingly. See `AFHTTPClientOperation` for further details.
|
||||||
|
|
||||||
|
## Subclassing Notes
|
||||||
|
|
||||||
|
In most cases, one should create an `AFHTTPClient` subclass for each website or web application that your application communicates with. It is often useful, also, to define a class method that returns a singleton shared HTTP client in each subclass, that persists authentication credentials and other configuration across the entire application.
|
||||||
|
|
||||||
|
## Methods to Override
|
||||||
|
|
||||||
|
To change the behavior of all url request construction for an `AFHTTPClient` subclass, override `requestWithMethod:path:parameters`.
|
||||||
|
|
||||||
|
## Default Headers
|
||||||
|
|
||||||
|
By default, `AFHTTPClient` sets the following HTTP headers:
|
||||||
|
|
||||||
- `Accept: application/json`
|
- `Accept: application/json`
|
||||||
- `Accept-Encoding: gzip`
|
- `Accept-Encoding: gzip`
|
||||||
|
|
@ -43,14 +60,6 @@ typedef enum {
|
||||||
- `User-Agent: #{generated user agent}`
|
- `User-Agent: #{generated user agent}`
|
||||||
|
|
||||||
You can override these HTTP headers or define new ones using `setDefaultHeader:value:`.
|
You can override these HTTP headers or define new ones using `setDefaultHeader:value:`.
|
||||||
|
|
||||||
# Subclassing Notes
|
|
||||||
|
|
||||||
It is strongly recommended that you create an `AFHTTPClient` subclass for each website or web application that your application communicates with, and in each subclass, defining a method that returns a singleton object that acts as single a shared HTTP client that holds authentication credentials and other configuration for the entire application.
|
|
||||||
|
|
||||||
## Methods to Override
|
|
||||||
|
|
||||||
If an `AFHTTPClient` wishes to change the way request parameters are encoded, then the base implementation of `requestWithMethod:path:parameters: should be overridden. Otherwise, it should be sufficient to take the `super` implementation, and configure the resulting `NSMutableURLRequest` object accordingly.
|
|
||||||
*/
|
*/
|
||||||
@interface AFHTTPClient : NSObject {
|
@interface AFHTTPClient : NSObject {
|
||||||
@private
|
@private
|
||||||
|
|
@ -162,13 +171,17 @@ typedef enum {
|
||||||
///-------------------------------
|
///-------------------------------
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates an `NSMutableURLRequest` object with the specified HTTP method and path. If the HTTP method is `GET`, the parameters will be used to construct a url-encoded query string that is appended to the request's URL. If `POST`, `PUT`, or `DELETE`, the parameters will be encoded into a `application/x-www-form-urlencoded` HTTP body.
|
Creates an `NSMutableURLRequest` object with the specified HTTP method and path. By default, this method scans through the registered operation classes (in reverse order of when they were specified), until finding one that can handle the specified request.
|
||||||
|
|
||||||
|
If the HTTP method is `GET`, the parameters will be used to construct a url-encoded query string that is appended to the request's URL. Otherwise, the parameters will be encoded according to the value of the `parameterEncoding` property, and set as the request body.
|
||||||
|
|
||||||
@param method The HTTP method for the request, such as `GET`, `POST`, `PUT`, or `DELETE`.
|
@param method The HTTP method for the request, such as `GET`, `POST`, `PUT`, or `DELETE`.
|
||||||
@param path The path to be appended to the HTTP client's base URL and used as the request URL.
|
@param path The path to be appended to the HTTP client's base URL and used as the request URL.
|
||||||
@param parameters The parameters to be either set as a query string for `GET` requests, or the request HTTP body.
|
@param parameters The parameters to be either set as a query string for `GET` requests, or the request HTTP body.
|
||||||
|
|
||||||
@return An `NSMutableURLRequest` object
|
@return An `NSMutableURLRequest` object
|
||||||
|
|
||||||
|
@see AFHTTPClientOperation
|
||||||
*/
|
*/
|
||||||
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
|
- (NSMutableURLRequest *)requestWithMethod:(NSString *)method
|
||||||
path:(NSString *)path
|
path:(NSString *)path
|
||||||
|
|
@ -184,6 +197,8 @@ typedef enum {
|
||||||
|
|
||||||
@see AFMultipartFormData
|
@see AFMultipartFormData
|
||||||
|
|
||||||
|
@warning An exception will be raised if the specified method is not `POST`, `PUT` or `DELETE`.
|
||||||
|
|
||||||
@return An `NSMutableURLRequest` object
|
@return An `NSMutableURLRequest` object
|
||||||
*/
|
*/
|
||||||
- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
|
- (NSMutableURLRequest *)multipartFormRequestWithMethod:(NSString *)method
|
||||||
|
|
@ -289,8 +304,27 @@ typedef enum {
|
||||||
|
|
||||||
#pragma mark -
|
#pragma mark -
|
||||||
|
|
||||||
@protocol AFHTTPClientOperation <NSObject>
|
/**
|
||||||
+ (BOOL)canProcessRequest:(NSURLRequest *)request;
|
The `AFHTTPClientOperation` protocol defines the methods used for the automatic content parsing functionality of `AFHTTPClient`.
|
||||||
|
|
||||||
|
@see `AFHTTPClient -registerHTTPOperationClass:`
|
||||||
|
*/
|
||||||
|
@protocol AFHTTPClientOperation
|
||||||
|
|
||||||
|
/**
|
||||||
|
A Boolean value determining whether or not the class can process the specified request. For example, `AFJSONRequestOperation` may check to make sure the content type was `application/json` or the URL path extension was `.json`.
|
||||||
|
|
||||||
|
@param urlRequest The request that is determined to be supported or not supported for this class.
|
||||||
|
*/
|
||||||
|
+ (BOOL)canProcessRequest:(NSURLRequest *)urlRequest;
|
||||||
|
|
||||||
|
/**
|
||||||
|
Constructs and initializes an operation with success and failure callbacks.
|
||||||
|
|
||||||
|
@param urlRequest The request used by the operation connection.
|
||||||
|
@param success A block object to be executed when the operation finishes successfully. The block has no return value and takes a single argument, the response object from the request.
|
||||||
|
@param failure A block object to be executed when the operation finishes unsuccessfully. The block has no return value and takes two arguments: the response received from the server, and the error describing the network or parsing error that occurred.
|
||||||
|
*/
|
||||||
+ (id)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
+ (id)HTTPRequestOperationWithRequest:(NSURLRequest *)urlRequest
|
||||||
success:(void (^)(id object))success
|
success:(void (^)(id object))success
|
||||||
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure;
|
failure:(void (^)(NSHTTPURLResponse *response, NSError *error))failure;
|
||||||
|
|
@ -300,6 +334,9 @@ typedef enum {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
The `AFMultipartFormData` protocol defines the methods supported by the parameter in the block argument of `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`.
|
The `AFMultipartFormData` protocol defines the methods supported by the parameter in the block argument of `multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`.
|
||||||
|
|
||||||
|
@see `AFHTTPClient -multipartFormRequestWithMethod:path:parameters:constructingBodyWithBlock:`
|
||||||
|
|
||||||
*/
|
*/
|
||||||
@protocol AFMultipartFormData
|
@protocol AFMultipartFormData
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue