FWHTTPSessionManager
@interface FWHTTPSessionManager
: FWURLSessionManager <NSSecureCoding, NSCopying>
FWHTTPSessionManager
-
The URL used to construct requests from relative paths in methods like
requestWithMethod:URLString:parameters:
, and theGET
/POST
/ et al. convenience methods.Declaration
Objective-C
@property (nonatomic, strong, readonly, nullable) NSURL *baseURL;
-
Requests created with
requestWithMethod:URLString:parameters:
&multipartFormRequestWithMethod:URLString:parameters:constructingBodyWithBlock:
are constructed with a set of default headers using a parameter serialization specified by this property. By default, this is set to an instance ofFWHTTPRequestSerializer
, which serializes query string parameters forGET
,HEAD
, andDELETE
requests, or otherwise URL-form-encodes HTTP message bodies.Warning
requestSerializer
must not benil
.Declaration
Objective-C
@property (nonatomic, strong) FWHTTPRequestSerializer<FWURLRequestSerialization> *_Nonnull requestSerializer;
-
Responses sent from the server in data tasks created with
dataTaskWithRequest:success:failure:
and run using theGET
/POST
/ et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance ofFWJSONResponseSerializer
.Warning
responseSerializer
must not benil
.Declaration
Objective-C
@property (nonatomic, strong) FWHTTPResponseSerializer<FWURLResponseSerialization> *_Nonnull responseSerializer;
-
The security policy used by created session to evaluate server trust for secure connections.
FWURLSessionManager
uses thedefaultPolicy
unless otherwise specified. A security policy configured withFWSSLPinningModePublicKey
orFWSSLPinningModeCertificate
can only be applied on a session manager initialized with a secure base URL (i.e. https). Applying a security policy with pinning enabled on an insecure session manager throws anInvalid Security Policy
exception.Declaration
Objective-C
@property (nonatomic, strong) FWSecurityPolicy *_Nonnull securityPolicy;
-
Creates and returns an
FWHTTPSessionManager
object.Declaration
Objective-C
+ (nonnull instancetype)manager;
-
Initializes an
FWHTTPSessionManager
object with the specified base URL.Declaration
Objective-C
- (nonnull instancetype)initWithBaseURL:(nullable NSURL *)url;
Parameters
url
The base URL for the HTTP client.
Return Value
The newly-initialized HTTP client
-
Initializes an
FWHTTPSessionManager
object with the specified base URL.This is the designated initializer.
Declaration
Objective-C
- (nonnull instancetype)initWithBaseURL:(nullable NSURL *)url sessionConfiguration: (nullable NSURLSessionConfiguration *)configuration;
Parameters
url
The base URL for the HTTP client.
configuration
The configuration used to create the managed session.
Return Value
The newly-initialized HTTP client
-
Creates and runs an
NSURLSessionDataTask
with aGET
request.See
-dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) GET:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers progress: (nullable void (^)(NSProgress *_Nonnull __strong))downloadProgress success:(nullable void (^)(NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
downloadProgress
A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with aHEAD
request.See
-dataTaskWithRequest:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) HEAD:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers success: (nullable void (^)(NSURLSessionDataTask *_Nonnull __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes a single arguments: the data task.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with aPOST
request.See
-dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) POST:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers progress:(nullable void (^)(NSProgress *_Nonnull __strong))uploadProgress success:(nullable void (^)(NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
uploadProgress
A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with a multipartPOST
request.See
-dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) POST:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *) headers constructingBodyWithBlock: (nullable void (^)(id<FWMultipartFormData> _Nonnull __strong))block progress:(nullable void (^)(NSProgress *_Nonnull __strong)) uploadProgress success:(nullable void (^)( NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)( NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
block
A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the
FWMultipartFormData
protocol.uploadProgress
A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with aPUT
request.See
-dataTaskWithRequest:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) PUT:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers success:(nullable void (^)(NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with aPATCH
request.See
-dataTaskWithRequest:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) PATCH:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers success:(nullable void (^)(NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
Creates and runs an
NSURLSessionDataTask
with aDELETE
request.See
-dataTaskWithRequest:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) DELETE:(nonnull NSString *)URLString parameters:(nullable id)parameters headers:(nullable NSDictionary<NSString *, NSString *> *)headers success:(nullable void (^)(NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)(NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
-
-dataTaskWithHTTPMethod:
URLString: parameters: headers: uploadProgress: downloadProgress: success: failure: Creates an
NSURLSessionDataTask
with a customHTTPMethod
request.See
-dataTaskWithRequest:uploadProgress:downloadProgress:completionHandler:
Declaration
Objective-C
- (nullable NSURLSessionDataTask *) dataTaskWithHTTPMethod:(nonnull NSString *)method URLString:(nonnull NSString *)URLString parameters:(nullable id)parameters headers: (nullable NSDictionary<NSString *, NSString *> *)headers uploadProgress: (nullable void (^)(NSProgress *_Nonnull __strong))uploadProgress downloadProgress: (nullable void (^)(NSProgress *_Nonnull __strong))downloadProgress success:(nullable void (^)( NSURLSessionDataTask *_Nonnull __strong, id _Nullable __strong))success failure:(nullable void (^)( NSURLSessionDataTask *_Nullable __strong, NSError *_Nonnull __strong))failure;
Parameters
method
The HTTPMethod string used to create the request.
URLString
The URL string used to create the request URL.
parameters
The parameters to be encoded according to the client request serializer.
headers
The headers appended to the default headers for this request.
uploadProgress
A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
downloadProgress
A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
success
A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
failure
A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.