Browse Source

Method now defaults to `.get` for request and download and `.post` for upload.

Christian Noon 9 years ago
parent
commit
722b701e40

+ 17 - 17
Source/Alamofire.swift

@@ -106,7 +106,7 @@ extension URLRequest {
 /// specified `urlString`, `method`, `parameters`, `encoding` and `headers`.
 ///
 /// - parameter urlString:  The URL string.
-/// - parameter method:     The HTTP method.
+/// - parameter method:     The HTTP method. `.get` by default.
 /// - parameter parameters: The parameters. `nil` by default.
 /// - parameter encoding:   The parameter encoding. `.url` by default.
 /// - parameter headers:    The HTTP headers. `nil` by default.
@@ -115,7 +115,7 @@ extension URLRequest {
 @discardableResult
 public func request(
     _ urlString: URLStringConvertible,
-    withMethod method: HTTPMethod,
+    method: HTTPMethod = .get,
     parameters: [String: Any]? = nil,
     encoding: ParameterEncoding = .url,
     headers: [String: String]? = nil)
@@ -123,7 +123,7 @@ public func request(
 {
     return SessionManager.default.request(
         urlString,
-        withMethod: method,
+        method: method,
         parameters: parameters,
         encoding: encoding,
         headers: headers
@@ -137,8 +137,8 @@ public func request(
 ///
 /// - returns: The created `DataRequest`.
 @discardableResult
-public func request(_ urlRequest: URLRequestConvertible) -> DataRequest {
-    return SessionManager.default.request(urlRequest.urlRequest)
+public func request(resource urlRequest: URLRequestConvertible) -> DataRequest {
+    return SessionManager.default.request(resource: urlRequest)
 }
 
 // MARK: - Download Request
@@ -229,8 +229,8 @@ public func download(
 /// and `headers` for uploading the `file`.
 ///
 /// - parameter file:      The file to upload.
-/// - parameter method:    The HTTP method.
 /// - parameter urlString: The URL string.
+/// - parameter method:    The HTTP method. `.post` by default.
 /// - parameter headers:   The HTTP headers. `nil` by default.
 ///
 /// - returns: The created `UploadRequest`.
@@ -238,11 +238,11 @@ public func download(
 public func upload(
     _ fileURL: URL,
     to urlString: URLStringConvertible,
-    withMethod method: HTTPMethod,
+    method: HTTPMethod = .post,
     headers: [String: String]? = nil)
     -> UploadRequest
 {
-    return SessionManager.default.upload(fileURL, to: urlString, withMethod: method, headers: headers)
+    return SessionManager.default.upload(fileURL, to: urlString, method: method, headers: headers)
 }
 
 /// Creates a `UploadRequest` using the default `SessionManager` from the specified `urlRequest` for
@@ -264,7 +264,7 @@ public func upload(_ fileURL: URL, with urlRequest: URLRequestConvertible) -> Up
 ///
 /// - parameter data:      The data to upload.
 /// - parameter urlString: The URL string.
-/// - parameter method:    The HTTP method.
+/// - parameter method:    The HTTP method. `.post` by default.
 /// - parameter headers:   The HTTP headers. `nil` by default.
 ///
 /// - returns: The created `UploadRequest`.
@@ -272,11 +272,11 @@ public func upload(_ fileURL: URL, with urlRequest: URLRequestConvertible) -> Up
 public func upload(
     _ data: Data,
     to urlString: URLStringConvertible,
-    withMethod method: HTTPMethod,
+    method: HTTPMethod = .post,
     headers: [String: String]? = nil)
     -> UploadRequest
 {
-    return SessionManager.default.upload(data, to: urlString, withMethod: method, headers: headers)
+    return SessionManager.default.upload(data, to: urlString, method: method, headers: headers)
 }
 
 /// Creates an `UploadRequest` using the default `SessionManager` from the specified `urlRequest` for
@@ -298,7 +298,7 @@ public func upload(_ data: Data, with urlRequest: URLRequestConvertible) -> Uplo
 ///
 /// - parameter stream:    The stream to upload.
 /// - parameter urlString: The URL string.
-/// - parameter method:    The HTTP method.
+/// - parameter method:    The HTTP method. `.post` by default.
 /// - parameter headers:   The HTTP headers. `nil` by default.
 ///
 /// - returns: The created `UploadRequest`.
@@ -306,11 +306,11 @@ public func upload(_ data: Data, with urlRequest: URLRequestConvertible) -> Uplo
 public func upload(
     _ stream: InputStream,
     to urlString: URLStringConvertible,
-    withMethod method: HTTPMethod,
+    method: HTTPMethod = .post,
     headers: [String: String]? = nil)
     -> UploadRequest
 {
-    return SessionManager.default.upload(stream, to: urlString, withMethod: method, headers: headers)
+    return SessionManager.default.upload(stream, to: urlString, method: method, headers: headers)
 }
 
 /// Creates an `UploadRequest` using the default `SessionManager` from the specified `urlRequest` for
@@ -347,14 +347,14 @@ public func upload(_ stream: InputStream, with urlRequest: URLRequestConvertible
 /// - parameter encodingMemoryThreshold: The encoding memory threshold in bytes.
 ///                                      `multipartFormDataEncodingMemoryThreshold` by default.
 /// - parameter urlString:               The URL string.
-/// - parameter method:                  The HTTP method.
+/// - parameter method:                  The HTTP method. `.post` by default.
 /// - parameter headers:                 The HTTP headers. `nil` by default.
 /// - parameter encodingCompletion:      The closure called when the `MultipartFormData` encoding is complete.
 public func upload(
     multipartFormData: @escaping (MultipartFormData) -> Void,
     usingThreshold encodingMemoryThreshold: UInt64 = SessionManager.multipartFormDataEncodingMemoryThreshold,
     to urlString: URLStringConvertible,
-    withMethod method: HTTPMethod,
+    method: HTTPMethod = .post,
     headers: [String: String]? = nil,
     encodingCompletion: ((SessionManager.MultipartFormDataEncodingResult) -> Void)?)
 {
@@ -362,7 +362,7 @@ public func upload(
         multipartFormData: multipartFormData,
         usingThreshold: encodingMemoryThreshold,
         to: urlString,
-        withMethod: method,
+        method: method,
         headers: headers,
         encodingCompletion: encodingCompletion
     )

+ 13 - 13
Source/SessionManager.swift

@@ -206,7 +206,7 @@ open class SessionManager {
     /// `parameters`, `encoding` and `headers`.
     ///
     /// - parameter urlString:  The URL string.
-    /// - parameter method:     The HTTP method.
+    /// - parameter method:     The HTTP method. `.get` by default.
     /// - parameter parameters: The parameters. `nil` by default.
     /// - parameter encoding:   The parameter encoding. `.url` by default.
     /// - parameter headers:    The HTTP headers. `nil` by default.
@@ -215,7 +215,7 @@ open class SessionManager {
     @discardableResult
     open func request(
         _ urlString: URLStringConvertible,
-        withMethod method: HTTPMethod,
+        method: HTTPMethod = .get,
         parameters: [String: Any]? = nil,
         encoding: ParameterEncoding = .url,
         headers: [String: String]? = nil)
@@ -224,17 +224,17 @@ open class SessionManager {
         let urlRequest = URLRequest(urlString: urlString, method: method, headers: headers)
         let encodedURLRequest = encoding.encode(urlRequest, parameters: parameters).0
 
-        return request(encodedURLRequest)
+        return request(resource: encodedURLRequest)
     }
 
     /// Creates a `DataRequest` to retrieve the contents of a URL based on the specified `urlRequest`.
     ///
     /// If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
     ///
-    /// - parameter urlRequest: The URL request
+    /// - parameter urlRequest: The URL request.
     ///
     /// - returns: The created `DataRequest`.
-    open func request(_ urlRequest: URLRequestConvertible) -> DataRequest {
+    open func request(resource urlRequest: URLRequestConvertible) -> DataRequest {
         let originalRequest = urlRequest.urlRequest
         let originalTask = DataRequest.Requestable(urlRequest: originalRequest)
 
@@ -358,8 +358,8 @@ open class SessionManager {
     /// If `startRequestsImmediately` is `true`, the request will have `resume()` called before being returned.
     ///
     /// - parameter file:      The file to upload.
-    /// - parameter method:    The HTTP method.
     /// - parameter urlString: The URL string.
+    /// - parameter method:    The HTTP method. `.post` by default.
     /// - parameter headers:   The HTTP headers. `nil` by default.
     ///
     /// - returns: The created `UploadRequest`.
@@ -367,7 +367,7 @@ open class SessionManager {
     open func upload(
         _ fileURL: URL,
         to urlString: URLStringConvertible,
-        withMethod method: HTTPMethod,
+        method: HTTPMethod = .post,
         headers: [String: String]? = nil)
         -> UploadRequest
     {
@@ -396,7 +396,7 @@ open class SessionManager {
     ///
     /// - parameter data:      The data to upload.
     /// - parameter urlString: The URL string.
-    /// - parameter method:    The HTTP method.
+    /// - parameter method:    The HTTP method. `.post` by default.
     /// - parameter headers:   The HTTP headers. `nil` by default.
     ///
     /// - returns: The created `UploadRequest`.
@@ -404,7 +404,7 @@ open class SessionManager {
     open func upload(
         _ data: Data,
         to urlString: URLStringConvertible,
-        withMethod method: HTTPMethod,
+        method: HTTPMethod = .post,
         headers: [String: String]? = nil)
         -> UploadRequest
     {
@@ -433,7 +433,7 @@ open class SessionManager {
     ///
     /// - parameter stream:    The stream to upload.
     /// - parameter urlString: The URL string.
-    /// - parameter method:    The HTTP method.
+    /// - parameter method:    The HTTP method. `.post` by default.
     /// - parameter headers:   The HTTP headers. `nil` by default.
     ///
     /// - returns: The created `UploadRequest`.
@@ -441,7 +441,7 @@ open class SessionManager {
     open func upload(
         _ stream: InputStream,
         to urlString: URLStringConvertible,
-        withMethod method: HTTPMethod,
+        method: HTTPMethod = .post,
         headers: [String: String]? = nil)
         -> UploadRequest
     {
@@ -486,14 +486,14 @@ open class SessionManager {
     /// - parameter encodingMemoryThreshold: The encoding memory threshold in bytes.
     ///                                      `multipartFormDataEncodingMemoryThreshold` by default.
     /// - parameter urlString:               The URL string.
-    /// - parameter method:                  The HTTP method.
+    /// - parameter method:                  The HTTP method. `.post` by default.
     /// - parameter headers:                 The HTTP headers. `nil` by default.
     /// - parameter encodingCompletion:      The closure called when the `MultipartFormData` encoding is complete.
     open func upload(
         multipartFormData: @escaping (MultipartFormData) -> Void,
         usingThreshold encodingMemoryThreshold: UInt64 = SessionManager.multipartFormDataEncodingMemoryThreshold,
         to urlString: URLStringConvertible,
-        withMethod method: HTTPMethod,
+        method: HTTPMethod = .post,
         headers: [String: String]? = nil,
         encodingCompletion: ((MultipartFormDataEncodingResult) -> Void)?)
     {

+ 5 - 5
Tests/AuthenticationTests.swift

@@ -68,7 +68,7 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .authenticate(user: "invalid", password: "credentials")
             .response { resp in
                 response = resp
@@ -92,7 +92,7 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .authenticate(user: user, password: password)
             .response { resp in
                 response = resp
@@ -123,7 +123,7 @@ class BasicAuthenticationTestCase: AuthenticationTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get, headers: headers)
+        manager.request(urlString, headers: headers)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -157,7 +157,7 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .authenticate(user: "invalid", password: "credentials")
             .response { resp in
                 response = resp
@@ -181,7 +181,7 @@ class HTTPDigestAuthenticationTestCase: AuthenticationTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .authenticate(user: user, password: password)
             .response { resp in
                 response = resp

+ 17 - 18
Tests/RequestTests.swift

@@ -32,7 +32,7 @@ class RequestInitializationTestCase: BaseTestCase {
         let urlString = "https://httpbin.org/"
 
         // When
-        let request = Alamofire.request(urlString, withMethod: .get)
+        let request = Alamofire.request(urlString)
 
         // Then
         XCTAssertNotNil(request.request)
@@ -46,7 +46,7 @@ class RequestInitializationTestCase: BaseTestCase {
         let urlString = "https://httpbin.org/get"
 
         // When
-        let request = Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        let request = Alamofire.request(urlString, parameters: ["foo": "bar"])
 
         // Then
         XCTAssertNotNil(request.request)
@@ -62,7 +62,7 @@ class RequestInitializationTestCase: BaseTestCase {
         let headers = ["Authorization": "123456"]
 
         // When
-        let request = Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"], headers: headers)
+        let request = Alamofire.request(urlString, parameters: ["foo": "bar"], headers: headers)
 
         // Then
         XCTAssertNotNil(request.request)
@@ -86,7 +86,7 @@ class RequestResponseTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -113,7 +113,7 @@ class RequestResponseTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .downloadProgress { progress in
                 progressValues.append((progress.completedUnitCount, progress.totalUnitCount))
             }
@@ -168,7 +168,7 @@ class RequestResponseTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .downloadProgress { progress in
                 progressValues.append((progress.completedUnitCount, progress.totalUnitCount))
             }
@@ -230,7 +230,7 @@ class RequestResponseTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .post, parameters: parameters)
+        Alamofire.request(urlString, method: .post, parameters: parameters)
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -282,7 +282,7 @@ class RequestResponseTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .post, parameters: parameters)
+        Alamofire.request(urlString, method: .post, parameters: parameters)
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -337,7 +337,7 @@ class RequestExtensionTestCase: BaseTestCase {
         var responses: [String] = []
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .preValidate {
                 responses.append("preValidate")
             }
@@ -369,7 +369,7 @@ class RequestDescriptionTestCase: BaseTestCase {
     func testRequestDescription() {
         // Given
         let urlString = "https://httpbin.org/get"
-        let request = Alamofire.request(urlString, withMethod: .get)
+        let request = Alamofire.request(urlString)
         let initialRequestDescription = request.description
 
         let expectation = self.expectation(description: "Request description should update: \(urlString)")
@@ -445,7 +445,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         let urlString = "https://httpbin.org/get"
 
         // When
-        let request = manager.request(urlString, withMethod: .get)
+        let request = manager.request(urlString)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -460,7 +460,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
 
         // When
         let headers = [ "Accept-Language": "en-GB" ]
-        let request = managerWithAcceptLanguageHeader.request(urlString, withMethod: .get, headers: headers)
+        let request = managerWithAcceptLanguageHeader.request(urlString, headers: headers)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -479,7 +479,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         let urlString = "https://httpbin.org/post"
 
         // When
-        let request = manager.request(urlString, withMethod: .post)
+        let request = manager.request(urlString, method: .post)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -499,7 +499,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         ]
 
         // When
-        let request = manager.request(urlString, withMethod: .post, parameters: parameters, encoding: .json)
+        let request = manager.request(urlString, method: .post, parameters: parameters, encoding: .json)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -530,7 +530,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         manager.session.configuration.httpCookieStorage?.setCookie(cookie)
 
         // When
-        let request = manager.request(urlString, withMethod: .post)
+        let request = manager.request(urlString, method: .post)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -555,7 +555,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         managerDisallowingCookies.session.configuration.httpCookieStorage?.setCookie(cookie)
 
         // When
-        let request = managerDisallowingCookies.request(urlString, withMethod: .post)
+        let request = managerDisallowingCookies.request(urlString, method: .post)
         let components = cURLCommandComponents(for: request)
 
         // Then
@@ -578,7 +578,6 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
                 multipartFormData.append(japaneseData, withName: "japanese")
             },
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case .success(let upload, _, _):
@@ -612,7 +611,7 @@ class RequestDebugDescriptionTestCase: BaseTestCase {
         let urlString = "invalid_url"
 
         // When
-        let request = manager.request(urlString, withMethod: .get)
+        let request = manager.request(urlString)
         let debugDescription = request.debugDescription
 
         // Then

+ 8 - 8
Tests/ResponseTests.swift

@@ -35,7 +35,7 @@ class ResponseDataTestCase: BaseTestCase {
         var response: DataResponse<Data>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseData { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -62,7 +62,7 @@ class ResponseDataTestCase: BaseTestCase {
         var response: DataResponse<Data>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseData { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -93,7 +93,7 @@ class ResponseStringTestCase: BaseTestCase {
         var response: DataResponse<String>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseString { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -120,7 +120,7 @@ class ResponseStringTestCase: BaseTestCase {
         var response: DataResponse<String>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseString { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -151,7 +151,7 @@ class ResponseJSONTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -178,7 +178,7 @@ class ResponseJSONTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -205,7 +205,7 @@ class ResponseJSONTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .get, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, parameters: ["foo": "bar"])
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -240,7 +240,7 @@ class ResponseJSONTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        Alamofire.request(urlString, withMethod: .post, parameters: ["foo": "bar"])
+        Alamofire.request(urlString, method: .post, parameters: ["foo": "bar"])
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()

+ 13 - 13
Tests/SessionDelegateTests.swift

@@ -76,7 +76,7 @@ class SessionDelegateTestCase: BaseTestCase {
         }
 
         // When
-        manager.request("https://httpbin.org/get", withMethod: .get).responseJSON { closureResponse in
+        manager.request("https://httpbin.org/get").responseJSON { closureResponse in
             response = closureResponse.response
             expectation.fulfill()
         }
@@ -101,7 +101,7 @@ class SessionDelegateTestCase: BaseTestCase {
         }
 
         // When
-        manager.request("https://httpbin.org/get", withMethod: .get).responseJSON { closureResponse in
+        manager.request("https://httpbin.org/get").responseJSON { closureResponse in
             response = closureResponse.response
             expectation.fulfill()
         }
@@ -125,7 +125,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -153,7 +153,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -188,7 +188,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -223,7 +223,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -258,7 +258,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -293,7 +293,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -337,7 +337,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -383,7 +383,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -435,7 +435,7 @@ class SessionDelegateTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        manager.request(urlString, withMethod: .get, headers: headers)
+        manager.request(urlString, headers: headers)
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()
@@ -470,7 +470,7 @@ class SessionDelegateTestCase: BaseTestCase {
         }
 
         // When
-        manager.request("https://httpbin.org/get", withMethod: .get).responseJSON { closureResponse in
+        manager.request("https://httpbin.org/get").responseJSON { closureResponse in
             response = closureResponse.response
             expectation.fulfill()
         }
@@ -495,7 +495,7 @@ class SessionDelegateTestCase: BaseTestCase {
         }
 
         // When
-        manager.request("https://httpbin.org/get", withMethod: .get).responseJSON { closureResponse in
+        manager.request("https://httpbin.org/get").responseJSON { closureResponse in
             response = closureResponse.response
             expectation.fulfill()
         }

+ 7 - 7
Tests/SessionManagerTests.swift

@@ -255,7 +255,7 @@ class SessionManagerTestCase: BaseTestCase {
         sessionManager.startRequestsImmediately = false
 
         // When
-        let request = sessionManager.request("https://httpbin.org/get", withMethod: .get)
+        let request = sessionManager.request("https://httpbin.org/get")
 
         // Then
         XCTAssertEqual(request.task.originalRequest?.httpMethod, adapter.method.rawValue)
@@ -286,7 +286,7 @@ class SessionManagerTestCase: BaseTestCase {
         sessionManager.startRequestsImmediately = false
 
         // When
-        let request = sessionManager.upload("data".data(using: .utf8)!, to: "https://httpbin.org/post", withMethod: .post)
+        let request = sessionManager.upload("data".data(using: .utf8)!, to: "https://httpbin.org/post")
 
         // Then
         XCTAssertEqual(request.task.originalRequest?.httpMethod, adapter.method.rawValue)
@@ -302,7 +302,7 @@ class SessionManagerTestCase: BaseTestCase {
 
         // When
         let fileURL = URL(fileURLWithPath: "/path/to/some/file.txt")
-        let request = sessionManager.upload(fileURL, to: "https://httpbin.org/post", withMethod: .post)
+        let request = sessionManager.upload(fileURL, to: "https://httpbin.org/post")
 
         // Then
         XCTAssertEqual(request.task.originalRequest?.httpMethod, adapter.method.rawValue)
@@ -318,7 +318,7 @@ class SessionManagerTestCase: BaseTestCase {
 
         // When
         let inputStream = InputStream(data: "data".data(using: .utf8)!)
-        let request = sessionManager.upload(inputStream, to: "https://httpbin.org/post", withMethod: .post)
+        let request = sessionManager.upload(inputStream, to: "https://httpbin.org/post")
 
         // Then
         XCTAssertEqual(request.task.originalRequest?.httpMethod, adapter.method.rawValue)
@@ -338,7 +338,7 @@ class SessionManagerTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        sessionManager.request("https://httpbin.org/basic-auth/user/password", withMethod: .get)
+        sessionManager.request("https://httpbin.org/basic-auth/user/password")
             .validate()
             .responseJSON { jsonResponse in
                 response = jsonResponse
@@ -366,7 +366,7 @@ class SessionManagerTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        sessionManager.request("https://httpbin.org/basic-auth/user/password", withMethod: .get)
+        sessionManager.request("https://httpbin.org/basic-auth/user/password")
             .validate()
             .responseJSON { jsonResponse in
                 response = jsonResponse
@@ -436,7 +436,7 @@ class SessionManagerConfigurationHeadersTestCase: BaseTestCase {
         var response: DataResponse<Any>?
 
         // When
-        manager.request("https://httpbin.org/headers", withMethod: .get)
+        manager.request("https://httpbin.org/headers")
             .responseJSON { closureResponse in
                 response = closureResponse
                 expectation.fulfill()

+ 14 - 14
Tests/TLSEvaluationTests.swift

@@ -84,7 +84,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -116,7 +116,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -152,7 +152,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -192,7 +192,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -226,7 +226,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -254,7 +254,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -282,7 +282,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -312,7 +312,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -346,7 +346,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -374,7 +374,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -402,7 +402,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -428,7 +428,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -460,7 +460,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()
@@ -490,7 +490,7 @@ class TLSEvaluationExpiredLeafCertificateTestCase: BaseTestCase {
         var error: Error?
 
         // When
-        manager.request(urlString, withMethod: .get)
+        manager.request(urlString)
             .response { resp in
                 error = resp.error
                 expectation?.fulfill()

+ 9 - 15
Tests/UploadTests.swift

@@ -33,7 +33,7 @@ class UploadFileInitializationTestCase: BaseTestCase {
         let imageURL = url(forResource: "rainbow", withExtension: "jpg")
 
         // When
-        let request = Alamofire.upload(imageURL, to: urlString, withMethod: .post)
+        let request = Alamofire.upload(imageURL, to: urlString)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -49,7 +49,7 @@ class UploadFileInitializationTestCase: BaseTestCase {
         let imageURL = url(forResource: "rainbow", withExtension: "jpg")
 
         // When
-        let request = Alamofire.upload(imageURL, to: urlString, withMethod: .post, headers: headers)
+        let request = Alamofire.upload(imageURL, to: urlString, method: .post, headers: headers)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -71,7 +71,7 @@ class UploadDataInitializationTestCase: BaseTestCase {
         let urlString = "https://httpbin.org/"
 
         // When
-        let request = Alamofire.upload(Data(), to: urlString, withMethod: .post)
+        let request = Alamofire.upload(Data(), to: urlString)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -86,7 +86,7 @@ class UploadDataInitializationTestCase: BaseTestCase {
         let headers = ["Authorization": "123456"]
 
         // When
-        let request = Alamofire.upload(Data(), to: urlString, withMethod: .post, headers: headers)
+        let request = Alamofire.upload(Data(), to: urlString, headers: headers)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -110,7 +110,7 @@ class UploadStreamInitializationTestCase: BaseTestCase {
         let imageStream = InputStream(url: imageURL)!
 
         // When
-        let request = Alamofire.upload(imageStream, to: urlString, withMethod: .post)
+        let request = Alamofire.upload(imageStream, to: urlString)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -127,7 +127,7 @@ class UploadStreamInitializationTestCase: BaseTestCase {
         let imageStream = InputStream(url: imageURL)!
 
         // When
-        let request = Alamofire.upload(imageStream, to: urlString, withMethod: .post, headers: headers)
+        let request = Alamofire.upload(imageStream, to: urlString, headers: headers)
 
         // Then
         XCTAssertNotNil(request.request, "request should not be nil")
@@ -153,7 +153,7 @@ class UploadDataTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        Alamofire.upload(data, to: urlString, withMethod: .post)
+        Alamofire.upload(data, to: urlString)
             .response { resp in
                 response = resp
                 expectation.fulfill()
@@ -190,7 +190,7 @@ class UploadDataTestCase: BaseTestCase {
         var response: DefaultDataResponse?
 
         // When
-        Alamofire.upload(data, to: urlString, withMethod: .post)
+        Alamofire.upload(data, to: urlString)
             .uploadProgress { progress in
                 uploadProgressValues.append((progress.completedUnitCount, progress.totalUnitCount))
             }
@@ -282,7 +282,7 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
                 formData = multipartFormData
             },
             to: urlString,
-            withMethod: .post,
+            method: .post,
             encodingCompletion: { result in
                 switch result {
                 case .success(let upload, _, _):
@@ -331,7 +331,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
                 multipartFormData.append(japaneseData, withName: "japanese")
             },
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case .success(let upload, _, _):
@@ -380,7 +379,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
                 multipartFormData.append(japaneseData, withName: "japanese")
             },
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case let .success(upload, uploadStreamingFromDisk, uploadStreamFileURL):
@@ -425,7 +423,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
                 formData = multipartFormData
             },
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case let .success(upload, uploadStreamingFromDisk, _):
@@ -480,7 +477,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
             },
             usingThreshold: 0,
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case let .success(upload, uploadStreamingFromDisk, uploadStreamFileURL):
@@ -530,7 +526,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
             },
             usingThreshold: 0,
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case let .success(upload, uploadStreamingFromDisk, _):
@@ -670,7 +665,6 @@ class UploadMultipartFormDataTestCase: BaseTestCase {
             },
             usingThreshold: streamFromDisk ? 0 : 100_000_000,
             to: urlString,
-            withMethod: .post,
             encodingCompletion: { result in
                 switch result {
                 case .success(let upload, _, _):

+ 22 - 22
Tests/ValidationTests.swift

@@ -38,7 +38,7 @@ class StatusCodeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(statusCode: 200..<300)
             .response { resp in
                 requestError = resp.error
@@ -70,7 +70,7 @@ class StatusCodeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(statusCode: [200])
             .response { resp in
                 requestError = resp.error
@@ -111,7 +111,7 @@ class StatusCodeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(statusCode: [])
             .response { resp in
                 requestError = resp.error
@@ -156,7 +156,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: ["application/json"])
             .validate(contentType: ["application/json;charset=utf8"])
             .validate(contentType: ["application/json;q=0.8;charset=utf8"])
@@ -192,7 +192,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: ["*/*"])
             .validate(contentType: ["application/*"])
             .validate(contentType: ["*/json"])
@@ -228,7 +228,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: ["application/octet-stream"])
             .response { resp in
                 requestError = resp.error
@@ -270,7 +270,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: [])
             .response { resp in
                 requestError = resp.error
@@ -312,7 +312,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: [])
             .response { resp in
                 requestError = resp.error
@@ -336,7 +336,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
     func testThatValidationForRequestWithAcceptableWildcardContentTypeResponseSucceedsWhenResponseIsNil() {
         // Given
         class MockManager: SessionManager {
-            override func request(_ urlRequest: URLRequestConvertible) -> DataRequest {
+            override func request(resource urlRequest: URLRequestConvertible) -> DataRequest {
                 let originalRequest = urlRequest.urlRequest
                 let adaptedRequest = originalRequest.adapt(using: adapter)
 
@@ -419,7 +419,7 @@ class ContentTypeValidationTestCase: BaseTestCase {
         var downloadResponse: DefaultDownloadResponse?
 
         // When
-        manager.request(urlString, withMethod: .delete)
+        manager.request(urlString, method: .delete)
             .validate(contentType: ["*/*"])
             .response { resp in
                 requestResponse = resp
@@ -467,7 +467,7 @@ class MultipleValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(statusCode: 200..<300)
             .validate(contentType: ["application/json"])
             .response { resp in
@@ -501,7 +501,7 @@ class MultipleValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(statusCode: 400..<600)
             .validate(contentType: ["application/octet-stream"])
             .response { resp in
@@ -544,7 +544,7 @@ class MultipleValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(contentType: ["application/octet-stream"])
             .validate(statusCode: 400..<600)
             .response { resp in
@@ -594,7 +594,7 @@ class AutomaticValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlRequest)
+        Alamofire.request(resource: urlRequest)
             .validate()
             .response { resp in
                 requestError = resp.error
@@ -626,7 +626,7 @@ class AutomaticValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate()
             .response { resp in
                 requestError = resp.error
@@ -669,7 +669,7 @@ class AutomaticValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlRequest)
+        Alamofire.request(resource: urlRequest)
             .validate()
             .response { resp in
                 requestError = resp.error
@@ -705,7 +705,7 @@ class AutomaticValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlRequest)
+        Alamofire.request(resource: urlRequest)
             .validate()
             .response { resp in
                 requestError = resp.error
@@ -739,7 +739,7 @@ class AutomaticValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlRequest)
+        Alamofire.request(resource: urlRequest)
             .validate()
             .response { resp in
                 requestError = resp.error
@@ -825,7 +825,7 @@ class CustomValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate { request, response, data in
                 guard data != nil else { return .failure(ValidationError.missingData) }
                 return .success
@@ -869,7 +869,7 @@ class CustomValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate { _, _, _ in .failure(ValidationError.missingData) }
             .validate { _, _, _ in .failure(ValidationError.missingFile) } // should be ignored
             .response { resp in
@@ -903,7 +903,7 @@ class CustomValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validateDataExists()
             .response { resp in
                 requestError = resp.error
@@ -935,7 +935,7 @@ class CustomValidationTestCase: BaseTestCase {
         var downloadError: Error?
 
         // When
-        Alamofire.request(urlString, withMethod: .get)
+        Alamofire.request(urlString)
             .validate(with: ValidationError.missingData)
             .validate(with: ValidationError.missingFile) // should be ignored
             .response { resp in