Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[10.x] Add newResponse method to PendingRequest #48344

Merged
merged 2 commits into from
Sep 11, 2023

Conversation

denniseilander
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants