Thanks Jon, I'm reading it right now.
public enum HTTPMethod: String { case connect, delete, ... }
[...] If you need to use an HTTP method that Alamofire's HTTPMethod type doesn't support, you can still set the String httpMethod property on URLRequest directly.
The closed enum was surprising (because I know there are exotic servers), but it is the sentence that had me write this message.
Is there a reason why HTTPMethod is defined as a closed enum instead of a raw representable type which accepts any string? It would allow Alamofire to support all HTTP methods out of the box, without making the life of users that remain in the strict context of RFC 7231 any more difficult:
public struct HTTPMethod: RawRepresentable {
public var rawValue: String
// Let users define their own methods
public init(rawValue: String) { self.rawValue = rawValue }
public static let connect = HTTPMethod(rawValue: "CONNECT")
public static let delete = HTTPMethod(rawValue: "DELETE")
...
}
This would avoid the kind of little inconsistencies that makes the life of developers miserable: when a tiny change (supporting an exotic HTTP method) requires heavy refactoring (we can no longer rely on the HTTPMethod type in our stack).
Edit
A few lines below, I have my answer with the ParameterEncoder protocol.
With my naive suggestion, exotic methods would sometimes have to raise a fatal error:
extension HTTPMethod {
static let exotic = HTTPMethod(rawValue: "EXOTIC")
}
// Fatal error: Please provide an explicit encoder,
// such as URLEncodedFormParameterEncoder(destination: .httpBody)
AF.request(
"https://httpbin.org/get",
method: .exotic,
parameters: parameters)
I don't know if Alamofire makes a liberal use of fatalError and preconditions in order to spot programmer mistakes (an ever-hot topic), so I won't elaborate more. I just want to say that in my humble opinion, this is still better than the closed enum, because of my argument above (a tiny change in an app shouldn't require heavy refactoring).