mohamedahmed01 / laravel-http-query-polyfill
Backward-compatible polyfill for Laravel's Http::query() method (RFC 10008) on Laravel < 13.19
Package info
github.com/mohamedahmed01/http-query-polyfill
pkg:composer/mohamedahmed01/laravel-http-query-polyfill
Requires
- php: ^8.1
- illuminate/http: ^10.0|^11.0|^12.0|^13.0
- illuminate/support: ^10.0|^11.0|^12.0|^13.0
Requires (Dev)
- guzzlehttp/guzzle: ^7.8
- orchestra/testbench: ^8.0|^9.0|^10.0|^11.0
- phpunit/phpunit: ^10.0|^11.0|^12.0
Suggests
- guzzlehttp/guzzle: Required to use the Laravel HTTP client (^7.8).
README
Backward-compatible polyfill for Http::query() introduced in Laravel 13.19.0 (RFC 10008).
On Laravel < 13.19, this package registers PendingRequest::query() so you can send HTTP QUERY requests with a body. On Laravel 13.19+, registration is skipped and the native method is used unchanged.
Installation
composer require mohamedahmed01/laravel-http-query-polyfill
The service provider is auto-discovered. No further setup is required.
Usage
Same API as Laravel 13.19+:
use Illuminate\Support\Facades\Http; $response = Http::query('https://api.example.com/search', [ 'filter' => ['status' => 'active'], ]);
JSON is the default body format. Use existing fluent helpers for other formats:
Http::asForm()->query('https://api.example.com/search', [ 'filter' => 'active', ]);
URL query strings are unchanged — keep using withQueryParameters() or Http::get($url, $query) for those.
Testing helpers (Laravel < 13.19)
Laravel 13.19 also added $this->query() / $this->queryJson() on HTTP tests. Those live on a trait, so they cannot be auto-registered. On older Laravel, add the polyfill trait to your base test case:
use Illuminate\Foundation\Testing\TestCase as BaseTestCase; use MohamedAhmed01\HttpQueryPolyfill\Testing\MakesHttpQueryRequests; abstract class TestCase extends BaseTestCase { use MakesHttpQueryRequests; }
Then:
$this->queryJson('/search', ['filter' => 'active'])->assertOk();
Do not use this trait on Laravel 13.19+ — the methods already exist and will collide.
Compatibility
| Laravel | Behavior |
|---|---|
| 10.x – 13.18 | Macro polyfill registered |
| 13.19+ | No-op; native Http::query() used |
Live integration (optional)
Against Ayder's /broker/query QUERY endpoint:
# from an Ayder checkout docker compose up -d --build curl -fsS http://127.0.0.1:1109/health # from this package vendor/bin/phpunit --filter AyderHttpQueryIntegrationTest
Coverage includes:
Http::query()with a JSON body against a real QUERY serverAccept-Query,ETag,Content-Location- conditional revalidation with
If-None-Match→304
Tests skip automatically when Ayder is not reachable. Override with AYDER_BASE_URL / AYDER_TOKEN.
License
MIT