Classes

The following classes are available globally.

  • Request subclass which handles in-memory Data download using URLSessionDataTask.

    See more

    Declaration

    Swift

    public class DataRequest : Request
  • Request subclass which streams HTTP response Data through a Handler closure.

    See more

    Declaration

    Swift

    public final class DataStreamRequest : Request
  • Request subclass which downloads Data to a file on disk using URLSessionDownloadTask.

    See more

    Declaration

    Swift

    public final class DownloadRequest : Request
  • Request is the common superclass of all Alamofire request types and provides common state, delegate, and callback handling.

    See more

    Declaration

    Swift

    public class Request
    extension Request: Equatable
    extension Request: Hashable
    extension Request: CustomStringConvertible
  • EventMonitor that provides Alamofire’s notifications.

    See more

    Declaration

    Swift

    public final class AlamofireNotifications : EventMonitor
  • A ParameterEncoder that encodes types as JSON body data.

    If no Content-Type header is already set on the provided URLRequests, it’s set to application/json.

    See more

    Declaration

    Swift

    open class JSONParameterEncoder : ParameterEncoder
  • A ParameterEncoder that encodes types as URL-encoded query strings to be set on the URL or as body data, depending on the Destination set.

    If no Content-Type header is already set on the provided URLRequests, it will be set to application/x-www-form-urlencoded; charset=utf-8.

    Encoding behavior can be customized by passing an instance of URLEncodedFormEncoder to the initializer.

    See more

    Declaration

    Swift

    open class URLEncodedFormParameterEncoder : ParameterEncoder
  • Session creates and manages Alamofire’s Request types during their lifetimes. It also provides common functionality for all Requests, including queuing, interception, trust management, redirect handling, and response cache handling.

    See more

    Declaration

    Swift

    open class Session
    extension Session: RequestDelegate
  • Class which implements the various URLSessionDelegate methods to connect various Alamofire features.

    See more

    Declaration

    Swift

    open class SessionDelegate : NSObject
    extension SessionDelegate: URLSessionDelegate
    extension SessionDelegate: URLSessionTaskDelegate
    extension SessionDelegate: URLSessionDataDelegate
    extension SessionDelegate: URLSessionWebSocketDelegate
    extension SessionDelegate: URLSessionDownloadDelegate
  • DataRequest subclass which handles Data upload from memory, file, or stream using URLSessionUploadTask.

    See more

    Declaration

    Swift

    public final class UploadRequest : DataRequest
  • The AuthenticationInterceptor class manages the queuing and threading complexity of authenticating requests. It relies on an Authenticator type to handle the actual URLRequest authentication and Credential refresh.

    See more

    Declaration

    Swift

    public class AuthenticationInterceptor<AuthenticatorType> : RequestInterceptor where AuthenticatorType : Authenticator
  • An EventMonitor which can contain multiple EventMonitors and calls their methods on their queues.

    See more

    Declaration

    Swift

    public final class CompositeEventMonitor : EventMonitor
  • EventMonitor that allows optional closures to be set to receive events.

    See more

    Declaration

    Swift

    open class ClosureEventMonitor : EventMonitor
  • Constructs multipart/form-data for uploads within an HTTP or HTTPS body. There are currently two ways to encode multipart form data. The first way is to encode the data directly in memory. This is very efficient, but can lead to memory issues if the dataset is too large. The second way is designed for larger datasets and will write all the data to a single file on disk with all the proper boundary segmentation. The second approach MUST be used for larger datasets such as video content, otherwise your app may run out of memory when trying to encode the dataset.

    For more information on multipart/form-data in general, please refer to the RFC-2388 and RFC-2045 specs as well and the w3 form documentation.

    See more

    Declaration

    Swift

    open class MultipartFormData
  • The NetworkReachabilityManager class listens for reachability changes of hosts and addresses for both cellular and WiFi network interfaces.

    Reachability can be used to determine background information about why a network operation failed, or to retry network requests when a connection is established. It should not be used to prevent a user from initiating a network request, as it’s possible that an initial request may be required to establish reachability.

    See more

    Declaration

    Swift

    open class NetworkReachabilityManager
  • Closure-based RequestAdapter.

    See more

    Declaration

    Swift

    open class Adapter : RequestInterceptor
  • Closure-based RequestRetrier.

    See more

    Declaration

    Swift

    open class Retrier : RequestInterceptor
  • RequestInterceptor which can use multiple RequestAdapter and RequestRetrier values.

    See more

    Declaration

    Swift

    open class Interceptor : RequestInterceptor

Data

  • A ResponseSerializer that performs minimal response checking and returns any response Data as-is. By default, a request returning nil or no data is considered an error. However, if the request has an HTTPMethod or the response has an HTTP status code valid for empty responses, then an empty Data value is returned.

    See more

    Declaration

    Swift

    public final class DataResponseSerializer : ResponseSerializer

String

  • A ResponseSerializer that decodes the response data as a String. By default, a request returning nil or no data is considered an error. However, if the request has an HTTPMethod or the response has an HTTP status code valid for empty responses, then an empty String is returned.

    See more

    Declaration

    Swift

    public final class StringResponseSerializer : ResponseSerializer

JSON

  • A ResponseSerializer that decodes the response data using JSONSerialization. By default, a request returning nil or no data is considered an error. However, if the request has an HTTPMethod or the response has an HTTP status code valid for empty responses, then an NSNull value is returned.

    Note

    This serializer is deprecated and should not be used. Instead, create concrete types conforming to Decodable and use a DecodableResponseSerializer.
    See more

    Declaration

    Swift

    @available(*, deprecated, message: "JSONResponseSerializer deprecated and will be removed in Alamofire 6. Use DecodableResponseSerializer instead.")
    public final class JSONResponseSerializer : ResponseSerializer

Decodable

  • A ResponseSerializer that decodes the response data as a generic value using any type that conforms to DataDecoder. By default, this is an instance of JSONDecoder. Additionally, a request returning nil or no data is considered an error. However, if the request has an HTTPMethod or the response has an HTTP status code valid for empty responses then an empty value will be returned. If the decoded type conforms to EmptyResponse, the type’s emptyValue() will be returned. If the decoded type is Empty, the .value instance is returned. If the decoded type does not conform to EmptyResponse and isn’t Empty, an error will be produced.

    See more

    Declaration

    Swift

    public final class DecodableResponseSerializer<T> : ResponseSerializer where T : Decodable
  • A retry policy that retries requests using an exponential backoff for allowed HTTP methods and HTTP status codes as well as certain types of networking errors.

    See more

    Declaration

    Swift

    open class RetryPolicy : RequestInterceptor

Server Trust Evaluators

  • An evaluator which uses the default server trust evaluation while allowing you to control whether to validate the host provided by the challenge. Applications are encouraged to always validate the host in production environments to guarantee the validity of the server’s certificate chain.

    See more

    Declaration

    Swift

    public final class DefaultTrustEvaluator : ServerTrustEvaluating
  • An evaluator which Uses the default and revoked server trust evaluations allowing you to control whether to validate the host provided by the challenge as well as specify the revocation flags for testing for revoked certificates. Apple platforms did not start testing for revoked certificates automatically until iOS 10.1, macOS 10.12 and tvOS 10.1 which is demonstrated in our TLS tests. Applications are encouraged to always validate the host in production environments to guarantee the validity of the server’s certificate chain.

    See more

    Declaration

    Swift

    public final class RevocationTrustEvaluator : ServerTrustEvaluating
  • Uses the pinned certificates to validate the server trust. The server trust is considered valid if one of the pinned certificates match one of the server certificates. By validating both the certificate chain and host, certificate pinning provides a very secure form of server trust validation mitigating most, if not all, MITM attacks. Applications are encouraged to always validate the host and require a valid certificate chain in production environments.

    See more

    Declaration

    Swift

    public final class PinnedCertificatesTrustEvaluator : ServerTrustEvaluating
  • Uses the pinned public keys to validate the server trust. The server trust is considered valid if one of the pinned public keys match one of the server certificate public keys. By validating both the certificate chain and host, public key pinning provides a very secure form of server trust validation mitigating most, if not all, MITM attacks. Applications are encouraged to always validate the host and require a valid certificate chain in production environments.

    See more

    Declaration

    Swift

    public final class PublicKeysTrustEvaluator : ServerTrustEvaluating
  • Uses the provided evaluators to validate the server trust. The trust is only considered valid if all of the evaluators consider it valid.

    See more

    Declaration

    Swift

    public final class CompositeTrustEvaluator : ServerTrustEvaluating
  • Disables all evaluation which in turn will always consider any server trust as valid.

    Note

    Instead of disabling server trust evaluation, it’s a better idea to configure systems to properly trust test certificates, as outlined in this Apple tech note.

    THIS EVALUATOR SHOULD NEVER BE USED IN PRODUCTION!

    See more

    Declaration

    Swift

    public final class DisabledTrustEvaluator : ServerTrustEvaluating
  • An object that encodes instances into URL-encoded query strings.

    ArrayEncoding can be used to configure how Array values are encoded. By default, the .brackets encoding is used, encoding array values with brackets for each value. e.g array[]=1&array[]=2.

    BoolEncoding can be used to configure how Bool values are encoded. By default, the .numeric encoding is used, encoding true as 1 and false as 0.

    DataEncoding can be used to configure how Data values are encoded. By default, the .deferredToData encoding is used, which encodes Data values using their default Encodable implementation.

    DateEncoding can be used to configure how Date values are encoded. By default, the .deferredToDate encoding is used, which encodes Dates using their default Encodable implementation.

    KeyEncoding can be used to configure how keys are encoded. By default, the .useDefaultKeys encoding is used, which encodes the keys directly from the Encodable implementation.

    KeyPathEncoding can be used to configure how paths within nested objects are encoded. By default, the .brackets encoding is used, which encodes each sub-key in brackets. e.g. parent[child][grandchild]=value.

    NilEncoding can be used to configure how nil Optional values are encoded. By default, the .dropKey encoding is used, which drops nil key / value pairs from the output entirely.

    SpaceEncoding can be used to configure how spaces are encoded. By default, the .percentEscaped encoding is used, replacing spaces with %20.

    This type is largely based on Vapor’s url-encoded-form project.

    See more

    Declaration

    Swift

    public final class URLEncodedFormEncoder