Closed o-nnerb closed 3 years ago
You can work with opaque type but I don't know very much about that technique
Great suggestion. I think we'll have to avoid Self
in the protocol so we can form an Array
of the items. It would probably work well without being a static func
:
protocol RequestParam {
/// Here the param can modify the `URLRequest` in any way necessary.
func buildParam(_ request: inout URLRequest)
}
struct Body: RequestParam {
...
public func buildParam(_ request: inout URLRequest) {
request.httpBody = data
}
}
We may also want to pass the URLSession
in case they need to modify that. This also opens the possibility for user-created params :)
Awesome suggestion! This will make request so much cleaner 👏🏻
I will keep this topic open so we can track PR and discuss at any time.
About URLSession, I guess that this could be pass to RequestParam or maybe to other protocol that extends RequestParam, so Request struct can call the function, for example, trackSession(_ session: URLSession)
, after request starts.
I would like to suggest a better and clean way to create declarative objects.
The idea is to make
RequestParam
a generic protocol with a static function like that: