In Alamofire 5 we added the ability to pass Encodable
types as request parameters. Currently, the methods to do so look like this:
open func request<Parameters: Encodable>(_ convertible: URLConvertible,
method: HTTPMethod = .get,
parameters: Parameters? = nil,
encoder: ParameterEncoder = URLEncodedFormParameterEncoder.default,
headers: HTTPHeaders? = nil,
interceptor: RequestInterceptor? = nil) -> DataRequest
However, I've realized that, without the request
overload we provide for compatibility with older, no generic parameters, this method can't be used without providing a parameters
value, as otherwise the compiler can't infer that type. Within this method we capture the various parameters into a generic struct that gets passed further into Alamofire, and I could pass that value our Empty
type as Optional<Empty>.none
, and then offer an additional request
overload that doesn't require parameters
. However, that seems suboptimal, so I'm wondering if there's a way to get the default value for parameters
to work the way I want, that is by allowing any type, but when one isn't provided, using some concrete value to represent no parameters.
Any ideas?