- 
                Notifications
    You must be signed in to change notification settings 
- Fork 34
Description
There is currently no way to specify request options in this SDK, which is a severe limitation when it comes to certain use-cases. To clarify with what I mean with options: It's request transport behaviors that cannot be expressed by the request URL, method, headers, or body, such as timeout or how many redirections to follow (if any).
We need to allow passing such options (the two above are crucial examples, though there may be more). In any case, we can start simple, with those two, and add more as a need comes up. The key part is figuring out how to architecturally enable this.
I believe we have two reasonable options:
- Either allow specifying options in our RequestDTO: This would nicely centralize responsibility in the DTO we already use for everything.
- Or we allow passing options to the HttpTransporter::sendmethod, via an optional second parameter: This would mean there are two touch points for how to make a request (theRequestDTO itself and this parameter), which is not as neat. But on the other hand, one may argue that these request options should be centrally set, or we could even allow providing simple callbacks that can dynamically determine the value to use based on the currentRequestthat will be made.
In any case, I believe we should introduce a new DTO RequestOptions (which would either be used as a Request property or a HttpTransporter::send parameter) - let's avoid the WordPress array $args pattern and keep things type-safe :)
For reference, this is the shape of our current Request DTO:
RequestArrayShape array{
    method: string,
    uri: string,
    headers: array<string, list<string>>,
    body?: string|null
}
The last thing to check that is crucial and may influence our decision is how this is handled by the relevant PSR implementations, including Guzzle. We'll want to make sure our implementation is interoperable with that.