evaisse / simple-http-bundle
A very simple symfony http client bundle built on the httpfoundation component (instead of guzzle), using cURL and cURL multi.
Installs: 180 126
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 11
Open Issues: 6
Requires
- php: ^8.0
- ext-curl: *
- ext-dom: *
- ext-json: *
- react/promise: ^2.2
- sensio/framework-extra-bundle: ^5.5 || ^6.0
- symfony/browser-kit: ^5.4 || ^6.0
- symfony/config: ^5.4 || ^6.0
- symfony/dependency-injection: ^5.4 || ^6.0
- symfony/event-dispatcher: ^5.4 || ^6.0
- symfony/http-foundation: ^5.4 || ^6.0
- symfony/http-kernel: ^5.4 || ^6.0
- symfony/mime: ^5.4 || ^6.0
- symfony/security-http: ^5.4 || ^6.0
- symfony/serializer: ^5.4 || ^6.0
- symfony/stopwatch: ^5.4 || ^6.0
- symfony/twig-bundle: ^5.4 || ^6.0
Requires (Dev)
- phpunit/phpunit: ^9.5
- roave/security-advisories: dev-latest
Conflicts
- symfony/serializer: 6.0.0
- dev-master
- v3.5.2
- V3.5.1
- v3.5.0
- v3.4.2
- v3.4.1
- v3.4.0
- v3.3.0
- v3.2.0
- v3.1.x-dev
- v3.1.9
- 3.1.8
- v3.1.7
- v3.1.6
- v3.1.5
- v3.1.4
- v3.1.3
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.12
- v3.0.11
- 3.0.10
- v3.0.9
- v3.0.8
- v3.0.7
- v3.0.6
- v3.0.5
- v3.0.4
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.2.11
- v2.2.10
- v2.2.9
- v2.2.8
- v2.2.7
- v2.2.6
- v2.2.5
- v2.2.4
- v2.2.3
- v2.2.2
- v2.2.0
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v1.0.4
- v1.0.2
- v1.0.1
- v0.4.1
- v0.3.8
- v0.3.7
- v0.3.6
- v0.3.5
- v0.3.4
- v0.3.2
- v0.3.1
- v0.3.0
- v0.2.7
- v0.2.6
- v0.2.5
- v0.2.4
- v0.2.3
- v0.2.2
- v0.2.1
- v0.1.8
- v0.1.7
- v0.1.6
- v0.1.5
- v0.1.4
- v0.1.3
- v0.1.2
- v0.1.1
- v0.1.0
- v0.0.2
- dev-dependabot/composer/symfony/http-kernel-6.0.20
- dev-dependabot/composer/twig/twig-3.4.3
- dev-dependabot/composer/symfony/framework-bundle-6.0.4
- dev-feature/tests
- dev-feature/fix-missing-props
- dev-feature/fix-header-index
- dev-release/2.2
- dev-feature/symfony4
- dev-Atirbal-patch-1
- dev-feature/reset-data-collector-v2
- dev-feature/fix-header-parsing
- dev-feature/add-debug-dump
- dev-feature/symfony3
- dev-feature/symfony2
- dev-feature/replay-api-request
This package is auto-updated.
Last update: 2024-10-31 12:03:22 UTC
README
While Still maintained, I recommand you to replace this bundle with the symfony/http-client with has better support and a handy plug-in support.
A symfony2/3/4/5 http client bundle built on the httpfoundation component (instead of guzzle), using cURL as engine.
Quickstart
Get the simple API
$http = $this->container->get('http'); $http = $this->get('http'); // same as try { $http->GET('http://httpbin.org/ip'); // yeah, that's all. } catch (\Symfony\Component\HttpKernel\Exception\HttpException $e) { // handle errors } try { $data = $http->POST('http://httpbin.org/post', $myArgs); } catch (\Symfony\Component\HttpKernel\Exception\HttpException $e) { // handle errors }
Easy routing with replacement syntax (similar to php frameworks like symfony2/laravel)
$data = $http->GET('http://httpbin.org/status/{code}', array( "code" => 200 )); // will call http://httpbin.org/status/200 $data = $http->GET('http://httpbin.org/status/{code}', array( "code" => 200, "foo" => "bar" )); // will call http://httpbin.org/status/200?foo=bar
Development features
The simple http bundle provide you a nice profiler toolbar addition
- Request/Response body & headers details
- Cookies handy panel
- External debug links (to remote profiler using X-Debug-Link header)
- Request timing displayed in the timeline panel
Replay feature
Add this to routing.yml file
_simple_http:
resource: "@SimpleHttpBundle/Controller/"
type: annotation
prefix: /_profiler/simple-http
or
_simple_http:
resource: '@SimpleHttpBundle/Resources/config/routing.yml'
You can now resend an http call directly from the profiler debug panel
Panels details
![Panels details] (https://raw.githubusercontent.com/evaisse/SimpleHttpBundle/master/Resources/doc/profiler-panels.png)
Toolbar block
![Toolbar block] (https://raw.githubusercontent.com/evaisse/SimpleHttpBundle/master/Resources/doc/profiler-toolbar.png)
Timeline panel
![Timeline panel] (https://raw.githubusercontent.com/evaisse/SimpleHttpBundle/master/Resources/doc/profiler-timeline.png)
Complete API
Complete api using transaction factory
$transac = $http->prepare('GET', 'http://httpbin.org/ip'); $transac->execute();
Parrallel execution
$a = $http->prepare('GET', 'http://httpbin.org/ip'); $b = $http->prepare('PUT', 'http://httpbin.org/put'); $c = $http->prepare('POST', 'http://httpbin.org/post'); $http->execute([ $a, $b, $c ]); $a->hasError() || $a->getResult(); $b->hasError() || $b->getResult(); $c->hasError() || $c->getResult();
JSON services
print $http->prepare('POST', 'http://httpbin.org/ip', $_SERVER) ->json() ->execute() ->getResult()['ip'];
File upload
$http->prepare('PUT', 'http://httpbin.org/put') ->addFile('f1', './myfile.txt') ->addFile('f2', './myfile.txt') ->execute(); $http->prepare('POST', 'http://httpbin.org/post', [ 'infos' => 'foo', 'bar' => 'so so', ]) ->addFile('f1', './myfile.txt') ->addFile('f2', './myfile.txt') ->execute();
Cookies persistance
$a = $http->prepare('GET', 'http://httpbin.org/ip'); $b = $http->prepare('PUT', 'http://httpbin.org/put'); $c = $http->prepare('POST', 'http://httpbin.org/post'); $cookies = $http->getDefaultCookieJar(); // $cookies = $http->getCookieJar($session); if you want to directly store in user session $http->execute([ $a, $b, $c ], $cookies); dump($cookies);
Promise usage
$stmt = $http->prepare('PUT', 'http://httpbin.org/put') $stmt->onSuccess(function ($data) { // handle data })->onError(function (\Symfony\Component\HttpKernel\Exception\HttpException $e) { // handle errors })->onFinish(function () { // like "finally" }); $http->execute([ $stmt ]);