AF - SwiftDocOrg/Alamofire GitHub Wiki
AF
Global namespace containing API for the default Session instance.
public enum AF
Methods
request(_:method:parameters:encoding:headers:interceptor:)
Creates a DataRequest using Session.default to retrieve the contents of the specified url using the
method, parameters, encoding, and headers provided.
public static func request(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> DataRequest
Parameters
- url: The
URLConvertiblevalue. - method: The
HTTPMethod,.getby default. - parameters: The
Parameters,nilby default. - encoding: The
ParameterEncoding,URLEncoding.defaultby default. - headers: The
HTTPHeaders,nilby default. - interceptor: The
RequestInterceptor,nilby default.
Returns
The created DataRequest.
request(_:method:parameters:encoder:headers:interceptor:)
Creates a DataRequest using Session.default to retrieve the contents of the specified url using the
method, parameters, encoding, and headers provided.
public static func request<Parameters: Encodable>(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> DataRequest
Parameters
- url: The
URLConvertiblevalue. - method: The
HTTPMethod,.getby default. - parameters: The
Encodableparameters,nilby default. - encoding: The
ParameterEncoder,URLEncodedFormParameterEncoder.defaultby default. - headers: The
HTTPHeaders,nilby default. - interceptor: The
RequestInterceptor,nilby default.
Returns
The created DataRequest.
request(_:interceptor:)
Creates a DataRequest using Session.default to execute the specified urlRequest.
public static func request(_ urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> DataRequest
Parameters
- urlRequest: The
URLRequestConvertiblevalue. - interceptor: The
RequestInterceptor,nilby default.
Returns
The created DataRequest.
download(_:method:parameters:encoding:headers:interceptor:to:)
Creates a DownloadRequest using Session.default to download the contents of the specified url to
the provided destination using the method, parameters, encoding, and headers provided.
public static func download(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoding: ParameterEncoding = URLEncoding.default, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequest
If destination is not specified, the download will be moved to a temporary location determined by Alamofire.
Parameters
- url: The
URLConvertiblevalue. - method: The
HTTPMethod,.getby default. - parameters: The
Parameters,nilby default. - encoding: The
ParameterEncoding,URLEncoding.defaultby default. - headers: The
HTTPHeaders,nilby default. - interceptor: The
RequestInterceptor,nilby default. - destination: The
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.
Returns
The created DownloadRequest.
download(_:method:parameters:encoder:headers:interceptor:to:)
Creates a DownloadRequest using Session.default to download the contents of the specified url to the
provided destination using the method, encodable parameters, encoder, and headers provided.
public static func download<Parameters: Encodable>(_ url: URLConvertible, method: HTTPMethod = .get, parameters: Parameters? = nil, encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequest
Parameters
- url: The
URLConvertiblevalue. - method: The
HTTPMethod,.getby default. - parameters: The
Encodableparameters,nilby default. - encoder: The
ParameterEncoder,URLEncodedFormParameterEncoder.defaultby default. - headers: The
HTTPHeaders,nilby default. - interceptor: The
RequestInterceptor,nilby default. - destination: The
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.
Returns
The created DownloadRequest.
download(_:interceptor:to:)
Creates a DownloadRequest using Session.default to execute the specified urlRequest and download
the result to the provided destination.
public static func download(_ urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequest
Parameters
- urlRequest: The
URLRequestConvertiblevalue. - interceptor: The
RequestInterceptor,nilby default. - destination: The
DownloadRequest.Destinationclosure used the determine the destination of the downloaded file.nilby default.
Returns
The created DownloadRequest.
download(resumingWith:interceptor:to:)
Creates a DownloadRequest using the Session.default from the resumeData produced from a previous
DownloadRequest cancellation to retrieve the contents of the original request and save them to the destination.
public static func download(resumingWith resumeData: Data, interceptor: RequestInterceptor? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequest
Parameters
- resumeData: The resume
Data. This is an opaque blob produced byURLSessionDownloadTaskwhen a task is cancelled. See Apple's documentation for more information. - interceptor: The
RequestInterceptor,nilby default. - destination: The
DownloadRequest.Destinationclosure used to determine the destination of the downloaded file.nilby default.
Returns
The created DownloadRequest.
upload(_:to:method:headers:interceptor:fileManager:)
Creates an UploadRequest for the given Data, URLRequest components, and RequestInterceptor.
public static func upload(_ data: Data, to convertible: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- data: The
Datato upload. - convertible:
URLConvertiblevalue to be used as theURLRequest'sURL. - method:
HTTPMethodfor theURLRequest..postby default. - headers:
HTTPHeadersvalue to be added to theURLRequest.nilby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(_:with:interceptor:fileManager:)
Creates an UploadRequest for the given Data using the URLRequestConvertible value and RequestInterceptor.
public static func upload(_ data: Data, with convertible: URLRequestConvertible, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- data: The
Datato upload. - convertible:
URLRequestConvertiblevalue to be used to create theURLRequest. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(_:to:method:headers:interceptor:fileManager:)
Creates an UploadRequest for the file at the given file URL, using a URLRequest from the provided
components and RequestInterceptor.
public static func upload(_ fileURL: URL, to convertible: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- fileURL: The
URLof the file to upload. - convertible:
URLConvertiblevalue to be used as theURLRequest'sURL. - method:
HTTPMethodfor theURLRequest..postby default. - headers:
HTTPHeadersvalue to be added to theURLRequest.nilby default. - interceptor:
RequestInterceptorvalue to be used by the returnedUploadRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(_:with:interceptor:fileManager:)
Creates an UploadRequest for the file at the given file URL using the URLRequestConvertible value and
RequestInterceptor.
public static func upload(_ fileURL: URL, with convertible: URLRequestConvertible, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- fileURL: The
URLof the file to upload. - convertible:
URLRequestConvertiblevalue to be used to create theURLRequest. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(_:to:method:headers:interceptor:fileManager:)
Creates an UploadRequest from the InputStream provided using a URLRequest from the provided components and
RequestInterceptor.
public static func upload(_ stream: InputStream, to convertible: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- stream: The
InputStreamthat provides the data to upload. - convertible:
URLConvertiblevalue to be used as theURLRequest'sURL. - method:
HTTPMethodfor theURLRequest..postby default. - headers:
HTTPHeadersvalue to be added to theURLRequest.nilby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(_:with:interceptor:fileManager:)
Creates an UploadRequest from the provided InputStream using the URLRequestConvertible value and
RequestInterceptor.
public static func upload(_ stream: InputStream, with convertible: URLRequestConvertible, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
Parameters
- stream: The
InputStreamthat provides the data to upload. - convertible:
URLRequestConvertiblevalue to be used to create theURLRequest. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.
upload(multipartFormData:to:usingThreshold:method:headers:interceptor:fileManager:)
Creates an UploadRequest for the multipart form data built using a closure and sent using the provided
URLRequest components and RequestInterceptor.
public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, to url: URLConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
It is important to understand the memory implications of uploading MultipartFormData. If the cumulative
payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
used for larger payloads such as video content.
The encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory
or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold,
encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
technique was used.
Parameters
- multipartFormData:
MultipartFormDatabuilding closure. - convertible:
URLConvertiblevalue to be used as theURLRequest'sURL. - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default. - method:
HTTPMethodfor theURLRequest..postby default. - headers:
HTTPHeadersvalue to be added to theURLRequest.nilby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.
Returns
The created UploadRequest.
upload(multipartFormData:with:usingThreshold:interceptor:fileManager:)
Creates an UploadRequest using a MultipartFormData building closure, the provided URLRequestConvertible
value, and a RequestInterceptor.
public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, with request: URLRequestConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
It is important to understand the memory implications of uploading MultipartFormData. If the cumulative
payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
used for larger payloads such as video content.
The encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory
or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold,
encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
technique was used.
Parameters
- multipartFormData:
MultipartFormDatabuilding closure. - request:
URLRequestConvertiblevalue to be used to create theURLRequest. - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.
Returns
The created UploadRequest.
upload(multipartFormData:to:usingThreshold:method:headers:interceptor:fileManager:)
Creates an UploadRequest for the prebuilt MultipartFormData value using the provided URLRequest components
and RequestInterceptor.
public static func upload(multipartFormData: MultipartFormData, to url: URLConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
It is important to understand the memory implications of uploading MultipartFormData. If the cumulative
payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
used for larger payloads such as video content.
The encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory
or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold,
encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
technique was used.
Parameters
- multipartFormData:
MultipartFormDatainstance to upload. - url:
URLConvertiblevalue to be used as theURLRequest'sURL. - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default. - method:
HTTPMethodfor theURLRequest..postby default. - headers:
HTTPHeadersvalue to be added to theURLRequest.nilby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerto be used if the form data exceeds the memory threshold and is written to disk before being uploaded..defaultinstance by default.
Returns
The created UploadRequest.
upload(multipartFormData:with:usingThreshold:interceptor:fileManager:)
Creates an UploadRequest for the prebuilt MultipartFormData value using the providing URLRequestConvertible
value and RequestInterceptor.
public static func upload(multipartFormData: MultipartFormData, with request: URLRequestConvertible, usingThreshold encodingMemoryThreshold: UInt64 = MultipartFormData.encodingMemoryThreshold, interceptor: RequestInterceptor? = nil, fileManager: FileManager = .default) -> UploadRequest
It is important to understand the memory implications of uploading MultipartFormData. If the cumulative
payload is small, encoding the data in-memory and directly uploading to a server is the by far the most
efficient approach. However, if the payload is too large, encoding the data in-memory could cause your app to
be terminated. Larger payloads must first be written to disk using input and output streams to keep the memory
footprint low, then the data can be uploaded as a stream from the resulting file. Streaming from disk MUST be
used for larger payloads such as video content.
The encodingMemoryThreshold parameter allows Alamofire to automatically determine whether to encode in-memory
or stream from disk. If the content length of the MultipartFormData is below the encodingMemoryThreshold,
encoding takes place in-memory. If the content length exceeds the threshold, the data is streamed to disk
during the encoding process. Then the result is uploaded as data or as a stream depending on which encoding
technique was used.
Parameters
- multipartFormData:
MultipartFormDatainstance to upload. - request:
URLRequestConvertiblevalue to be used to create theURLRequest. - encodingMemoryThreshold: Byte threshold used to determine whether the form data is encoded into memory or onto disk before being uploaded.
MultipartFormData.encodingMemoryThresholdby default. - interceptor:
RequestInterceptorvalue to be used by the returnedDataRequest.nilby default. - fileManager:
FileManagerinstance to be used by the returnedUploadRequest..defaultinstance by default.
Returns
The created UploadRequest.