-
Creates a
DataRequest
usingSessionManager.default
to retrive the contents of the specifiedurl
using themethod
,parameters
,encoding
, andheaders
provided.Declaration
Swift
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
URLConvertible
value.method
The
HTTPMethod
,.get
by default.parameters
The
Parameters
,nil
by default.encoding
The
ParameterEncoding
,URLEncoding.default
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
DataRequest
. -
Creates a
DataRequest
usingSessionManager.default
to retrive the contents of the specifiedurl
using themethod
,parameters
,encoding
, andheaders
provided.Declaration
Swift
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
URLConvertible
value.method
The
HTTPMethod
,.get
by default.parameters
The
Encodable
parameters,nil
by default.encoding
The
ParameterEncoding
,URLEncodedFormParameterEncoder.default
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
DataRequest
. -
Creates a
DataRequest
usingSessionManager.default
to execute the specifiedurlRequest
.Declaration
Swift
public static func request(_ urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> DataRequest
Parameters
urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
DataRequest
.
-
Creates a
DownloadRequest
usingSessionManager.default
to download the contents of the specifiedurl
to the provideddestination
using themethod
,parameters
,encoding
, andheaders
provided.If
destination
is not specified, the download will remain at the temporary location determined by the underlyingURLSession
.Declaration
Swift
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
Parameters
url
The
URLConvertible
value.method
The
HTTPMethod
,.get
by default.parameters
The
Parameters
,nil
by default.encoding
The
ParameterEncoding
,URLEncoding.default
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.destination
The
DownloadRequest.Destination
closure used the determine the destination of the downloaded file.nil
by default.Return Value
The created
DownloadRequest
. -
Creates a
DownloadRequest
usingSessionManager.default
to download the contents of the specifiedurl
to the provideddestination
using themethod
, encodableparameters
,encoder
, andheaders
provided.If
destination
is not specified, the download will remain at the temporary location determined by the underlyingURLSession
.Declaration
Swift
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
URLConvertible
value.method
The
HTTPMethod
,.get
by default.parameters
The
Encodable
parameters,nil
by default.encoder
The
ParameterEncoder
,URLEncodedFormParameterEncoder.default
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.destination
The
DownloadRequest.Destination
closure used the determine the destination of the downloaded file.nil
by default.Return Value
The created
DownloadRequest
.
-
Creates a
DownloadRequest
usingSessionManager.default
to execute the specifiedurlRequest
and download the result to the provideddestination
.Declaration
Swift
public static func download(_ urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil, to destination: DownloadRequest.Destination? = nil) -> DownloadRequest
Parameters
urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.destination
The
DownloadRequest.Destination
closure used the determine the destination of the downloaded file.nil
by default.Return Value
The created
DownloadRequest
.
-
Creates a
DownloadRequest
using theSessionManager.default
from theresumeData
produced from a previousDownloadRequest
cancellation to retrieve the contents of the original request and save them to thedestination
.If
destination
is not specified, the contents will remain in the temporary location determined by the underlying URL session.On some versions of all Apple platforms (iOS 10 - 10.2, macOS 10.12 - 10.12.2, tvOS 10 - 10.1, watchOS 3 - 3.1.1),
resumeData
is broken on background URL session configurations. There’s an underlying bug in theresumeData
generation logic where the data is written incorrectly and will always fail to resume the download. For more information about the bug and possible workarounds, please refer to the this Stack Overflow post.Declaration
Swift
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 byURLSessionDownloadTask
when a task is cancelled. See Apple’s documentation for more information.interceptor
The
RequestInterceptor
,nil
by default.destination
The
DownloadRequest.Destination
closure used to determine the destination of the downloaded file.nil
by default.Return Value
The created
DownloadRequest
.
-
Creates an
UploadRequest
usingSessionManager.default
to upload the contents of thefileURL
specified using theurl
,method
andheaders
provided.Declaration
Swift
public static func upload(_ fileURL: URL, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
fileURL
The
URL
of the file to upload.url
The
URLConvertible
value.method
The
HTTPMethod
,.post
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
. -
Creates an
UploadRequest
using theSessionManager.default
to upload the contents of thefileURL
specificed using theurlRequest
provided.Declaration
Swift
public static func upload(_ fileURL: URL, with urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
fileURL
The
URL
of the file to upload.urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
.
-
Creates an
UploadRequest
usingSessionManager.default
to upload the contents of thedata
specified using theurl
,method
andheaders
provided.Declaration
Swift
public static func upload(_ data: Data, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
data
The
Data
to upload.url
The
URLConvertible
value.method
The
HTTPMethod
,.post
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.retryPolicies
The
RetryPolicy
types,[]
by default.Return Value
The created
UploadRequest
. -
Creates an
UploadRequest
usingSessionManager.default
to upload the contents of thedata
specified using theurlRequest
provided.Declaration
Swift
public static func upload(_ data: Data, with urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
data
The
Data
to upload.urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
.
-
Creates an
UploadRequest
usingSessionManager.default
to upload the content provided by thestream
specified using theurl
,method
andheaders
provided.Declaration
Swift
public static func upload(_ stream: InputStream, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
stream
The
InputStream
to upload.url
The
URLConvertible
value.method
The
HTTPMethod
,.post
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
. -
Creates an
UploadRequest
usingSessionManager.default
to upload the content provided by thestream
specified using theurlRequest
specified.Declaration
Swift
public static func upload(_ stream: InputStream, with urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
stream
The
InputStream
to upload.urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
.
-
Encodes
multipartFormData
usingencodingMemoryThreshold
and uploads the result usingSessionManager.default
with theurl
,method
, andheaders
provided.It is important to understand the memory implications of uploading
MultipartFormData
. If the cummulative 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 theMultipartFormData
is below theencodingMemoryThreshold
, 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.Declaration
Swift
public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold, to url: URLConvertible, method: HTTPMethod = .post, headers: HTTPHeaders? = nil, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
multipartFormData
The closure used to append body parts to the
MultipartFormData
.encodingMemoryThreshold
The encoding memory threshold in bytes.
10_000_000
bytes by default.url
The
URLConvertible
value.method
The
HTTPMethod
,.post
by default.headers
The
HTTPHeaders
,nil
by default.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The created
UploadRequest
. -
Encodes
multipartFormData
usingencodingMemoryThreshold
and uploads the result usingSessionManager.default
using theurlRequest
provided.It is important to understand the memory implications of uploading
MultipartFormData
. If the cummulative 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 theMultipartFormData
is below theencodingMemoryThreshold
, 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.Declaration
Swift
@discardableResult public static func upload(multipartFormData: @escaping (MultipartFormData) -> Void, usingThreshold encodingMemoryThreshold: UInt64 = MultipartUpload.encodingMemoryThreshold, with urlRequest: URLRequestConvertible, interceptor: RequestInterceptor? = nil) -> UploadRequest
Parameters
multipartFormData
The closure used to append body parts to the
MultipartFormData
.encodingMemoryThreshold
The encoding memory threshold in bytes.
10_000_000
bytes by default.urlRequest
The
URLRequestConvertible
value.interceptor
The
RequestInterceptor
,nil
by default.Return Value
The
UploadRequest
created.