[11.x] Introduce method Http::createPendingRequest()
#50980
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR introduces a new public method to the HTTP Factory.
Currently, the HTTP factory does not provide any method to return an instance of
PendingRequest
which would not have side-effects.Imagine a scenario, where we'd like to encapsulate clients for multiple services, which require API calls. To do that, we'd like to use the
PendingRequest
and have each client configure the underlyingPendingRequest
, if it needs any special configuration.The sample code might look as follows:
Currently, there is no way to instantiate a
PendingRequest
without calling a method from the underlying Factory. However, none of these methods return just aPendingRequest
instance, all of them have a side-effect.At the same time, we cannot simply use dependency injection or the container to instantiate a new
PendingRequest
, because we'd lose the global middleware, global options, stubs & preventing stray requests, which are provided by the underlying Factory through its__call
&newPendingRequest
methods.Hence why I suggest to either add a new method to the factory, or make the
newPendingRequest
method public (which, however, would be a breaking change and likely not a viable solution, unless targeting 12.x).