[10.x] Add newResponse method to PendingRequest #48344
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.
Laravel's Http Client is really useful, but it doesn't let you change the type of Response you get.
Why Do We Need This?
Some APIs don't use regular HTTP status codes. Instead, they put the status right into the data they send back and always return a 200 status code. Because of this, you might want to change the successful method on the
Response
class to look at the payload instead of the HTTP status.The Problem
You can usually make these changes by making your own version of the PendingRequest class. But, doing this breaks the built-in "retry" feature. This is because of the way
new Response()
is set in the code.The Fix
This PR adds a
newResponse
method to the PendingRequest. Now, you can make your own version of PendingRequest and use this method to return your own type of Response.Impact
This is a small change, but it makes the Http Client much more flexible. This is especially helpful if you're working with APIs that act in non-standard ways.