FWHTTPSessionManager


@interface FWHTTPSessionManager
    : FWURLSessionManager <NSSecureCoding, NSCopying>

FWHTTPSessionManager

  • The URL used to construct requests from relative paths in methods like requestWithMethod:URLString:parameters:, and the GET / 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 of FWHTTPRequestSerializer, which serializes query string parameters for GET, HEAD, and DELETE requests, or otherwise URL-form-encodes HTTP message bodies.

    Warning

    requestSerializer must not be nil.

    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 the GET / POST / et al. convenience methods are automatically validated and serialized by the response serializer. By default, this property is set to an instance of FWJSONResponseSerializer.

    Warning

    responseSerializer must not be nil.

    Declaration

    Objective-C

    @property (nonatomic, strong) FWHTTPResponseSerializer<FWURLResponseSerialization> *_Nonnull responseSerializer;

Managing Security Policy

  • The security policy used by created session to evaluate server trust for secure connections. FWURLSessionManager uses the defaultPolicy unless otherwise specified. A security policy configured with FWSSLPinningModePublicKey or FWSSLPinningModeCertificate 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 an Invalid Security Policy exception.

    Declaration

    Objective-C

    @property (nonatomic, strong) FWSecurityPolicy *_Nonnull securityPolicy;

Initialization

  • 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

Making HTTP Requests

  • Creates and runs an NSURLSessionDataTask with a GET 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 a HEAD 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 a POST 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 multipart POST 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 a PUT 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 a PATCH 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 a DELETE 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.

  • Creates an NSURLSessionDataTask with a custom HTTPMethod 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.