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

[11.x] Added support for passing custom JSON flags in the http client response factory. #54492

Conversation

maxwellmezadre
Copy link

@maxwellmezadre maxwellmezadre commented Feb 6, 2025

Adds support for passing custom JSON flags in the HTTP client response factory. When the body is an array, it is now encoded using the provided JSON flags, which allows developers to preserve specific numeric formatting (e.g. trailing zeros with JSON_PRESERVE_ZERO_FRACTION) when needed.

Before

Http::fake(
    '*' => Http::response(['value' => 10.0])
);

// When making a request:
$response = Http::get('https://example.com');
// The response JSON returns:
// ["value" => 10]

After

Http::fake(
    '*' => Http::response(['value' => 10.0], flags: JSON_PRESERVE_ZERO_FRACTION)
);

// When making a request:
$response = Http::get('https://example.com');
// The response JSON returns:
// ["value" => 10.0]

Co-authored-by: Sebastian Hädrich <11225821+shaedrich@users.noreply.github.com>
@taylorotwell
Copy link
Member

Thanks for your pull request to Laravel!

Unfortunately, I'm going to delay merging this code for now. To preserve our ability to adequately maintain the framework, we need to be very careful regarding the amount of code we include.

If applicable, please consider releasing your code as a package so that the community can still take advantage of your contributions!

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.

3 participants