immobiliare / RealHTTP

🌀swift async http client - fast, lightweight, type-safe
MIT License
282 stars 28 forks source link

Explicitly specify boolEncoding and arrayEncoding strategies when adding parameters in bulk via formURLEncodedBody() #67

Closed nashfive closed 2 years ago

nashfive commented 2 years ago

What problem are you facing?

I have a private method in my custom client to build my HTTPRequests as follow:

func buildRequest(
        path: String,
        method: HTTPMethod,
        parameters: HTTPRequestParametersDict?,
        timeout: TimeInterval?
    ) -> HTTPRequest {
        let request = HTTPRequest {
            $0.method = method
            $0.path = path
            $0.timeout = timeout

            if let parameters = parameters {
                $0.body = .formURLEncodedBody(defaultParameters.merging(parameters, uniquingKeysWith: { $1 }))
            } else {
                $0.body = .formURLEncodedBody(defaultParameters)
            }
        }
        return request
    }

The problem with this is that I couldn't find a way to specify the boolEncoding and arrayEncoding.

So my question is: Is there a way to specify it without iterating over all the parameters and manually use the request.addParameter(..., boolEncoding:, arrayEncoding:)? Or do you seen it as a new feature, like specifying it in the .formURLEncodedBody() method ?

Other Information

No response

malcommac commented 2 years ago

Hi @nashfive, currently, there is no a way to explicitly declare it. However, I exposed both of them inside the formURLEncodedBody() in order to avoid iterating over each parameter which, obviously does not make sense. You will find in 1.8.0.