RFC: Encodable Request Parameters


(Jon Shier) #1

I've finally completed an initial PR to add encodable request parameter support to Alamofire 5. This includes a custom URLEncodedFormEncoder implementation, mostly based on Vapor's encoder of the same name. You can find the implementation of this encoder here.

This RFC seeks comments on any addition encodable support, the implementation of the encoder, or general features around encodable parameters.


(Matt Eaton) #2

Well done. I like the implementation of auto-updating the 'Content-Type' to
"application/x-www-form-urlencoded; charset=utf-8" so the parameters can be mapped to the HTTP Body.

...
} else {
    if request.httpHeaders["Content-Type"] == nil {
        request.httpHeaders.update(.contentType("application/x-www-form-urlencoded; charset=utf-8"))
    }
     request.httpBody = try Result<Data> { try encoder.encode(parameters) }
                        .mapError { AFError.parameterEncoderFailed(reason: .encoderFailed(error: $0)) }.unwrap()
}
...