{"id":18926927,"url":"https://github.com/bedrockstreaming/guzzlehttpbundle","last_synced_at":"2025-06-27T06:39:43.479Z","repository":{"id":33937886,"uuid":"37662165","full_name":"BedrockStreaming/GuzzleHttpBundle","owner":"BedrockStreaming","description":"Symfony bundle on top of Guzzle","archived":false,"fork":false,"pushed_at":"2024-02-20T14:31:08.000Z","size":195,"stargazers_count":17,"open_issues_count":2,"forks_count":10,"subscribers_count":49,"default_branch":"master","last_synced_at":"2025-06-19T21:07:05.946Z","etag":null,"topics":["http","php","symfony-bundle"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BedrockStreaming.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-06-18T13:49:31.000Z","updated_at":"2024-08-01T09:36:11.000Z","dependencies_parsed_at":"2024-06-19T13:40:07.482Z","dependency_job_id":null,"html_url":"https://github.com/BedrockStreaming/GuzzleHttpBundle","commit_stats":{"total_commits":111,"total_committers":32,"mean_commits":3.46875,"dds":0.8378378378378378,"last_synced_commit":"c81c5adcb3c6c4fbc202971a75d8a0b4576849fb"},"previous_names":[],"tags_count":56,"template":false,"template_full_name":null,"purl":"pkg:github/BedrockStreaming/GuzzleHttpBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BedrockStreaming%2FGuzzleHttpBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BedrockStreaming%2FGuzzleHttpBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BedrockStreaming%2FGuzzleHttpBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BedrockStreaming%2FGuzzleHttpBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BedrockStreaming","download_url":"https://codeload.github.com/BedrockStreaming/GuzzleHttpBundle/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BedrockStreaming%2FGuzzleHttpBundle/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262209661,"owners_count":23275471,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["http","php","symfony-bundle"],"created_at":"2024-11-08T11:17:33.055Z","updated_at":"2025-06-27T06:39:43.455Z","avatar_url":"https://github.com/BedrockStreaming.png","language":"PHP","readme":"# GuzzleHttpBundle\n\n[![Build Status](https://github.com/BedrockStreaming/GuzzleHttpBundle/actions/workflows/ci.yml/badge.svg)](https://github.com/BedrockStreaming/GuzzleHttpBundle/actions/workflows/ci.yml) [![Latest Stable Version](http://poser.pugx.org/m6web/guzzle-http-bundle/v)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![Total Downloads](http://poser.pugx.org/m6web/guzzle-http-bundle/downloads)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![License](http://poser.pugx.org/m6web/guzzle-http-bundle/license)](https://packagist.org/packages/m6web/guzzle-http-bundle) [![PHP Version Require](http://poser.pugx.org/m6web/guzzle-http-bundle/require/php)](https://packagist.org/packages/m6web/guzzle-http-bundle)\n\nThe GuzzleHttpBundle provide Guzzle clients as Symfony services.\n\n## Installation\n\nRequire the bundle with Composer:\n\n```bash\n$ composer require m6web/guzzle-http-bundle \n```\n\n\u003e For older Symfony versions, you can try to install an older version of this bundle.\n\nIf you don't use Symfony Flex, register the bundle in your kernel:\n\n```php\n\nreturn [\n    // ...\n    M6Web\\Bundle\\GuzzleHttpBundle\\M6WebGuzzleHttpBundle =\u003e ['all' =\u003e true],\n]\n```\n\n## Usage\n\nAdd the `m6web_guzzlehttp` section in your configuration file. Here is the minimal configuration required.\n\n```yaml\n# app/config/config.yml\nm6web_guzzlehttp:\n    clients:\n        default: ~\n        other:\n            base_uri: \"http://domain.tld/\"\n```\n\nAll subkey under clients defines an instance of guzzle http client. These services are named `m6web_guzzlehttp_`+subkey expect for the\n `default` subkey that define the main service `m6web_guzzlehttp`.\n\nThen you can ask container for your client:\n\n```php\n// in a controller\n\n$client = $this-\u003eget('m6web_guzzlehttp'); // default client\n\ntry {\n    $response = $client-\u003eget('http://domain.tld/path/to/resource');\n\n    $promises = [\n        'first' =\u003e $client-\u003egetAsync('http://domain.tld/path/to/resource'),\n        'second' =\u003e $client-\u003egetAsync('http://domain.tld/path/to/other/resource')\n    ];\n\n    $result = \\GuzzleHttp\\Promise\\Utils::unwrap($promises);\n} catch(\\GuzzleHttp\\Exception\\ConnectException $e) {\n    // connection problem like timeout\n}\n\n// use other client\n$otherClient = $this-\u003eget('m6web_guzzlehttp_other');\n$response = $otherClient-\u003eget('path/to/resource'); // call http://domain.tld/path/to/resource\n```\n\nThe service return a configured guzzle client, for more information on how to use it, you can read the [guzzle6 documentation](http://guzzle.readthedocs.org/en/latest/index.html).\n\nThe only difference with guzzle6 reside in usage of curl for the redirect responses. You can choose to have the guzzle behavior\nfor redirection by setting the configuration key `redirect_handler` to `guzzle`.\n\nWhen a cache system is available, you can use `cache_force` and `cache_ttl` in addition of guzzle options than respectively\n force clear cache before request and use a specific ttl to a request that override configuration.\n\n ```php\n $client = $this-\u003eget('m6web_guzzlehttp');\n\n $response = $client-\u003eget('http://domain.tld', ['cache_force' =\u003e true]); // remove cache entry and set a new one\n\n $response = $client-\u003eget('http://doamin.tld/path', ['cache_ttl' =\u003e 200]); // set ttl to 200 seconds instead the default one\n\n ```\n\n## DataCollector\n\nA data collector is available when the Symfony profiler is enabled. \n\nIt allows you to inspect the following data:\n\n - Method\n - Url\n - Response code and reason\n - Execution time\n - Redirect count\n - Redirect time\n - Cache hit\n - Cache TTL\n\n**NOTE:** If you choose Guzzle for `redirect_handler`, The redirect count and redirect time will always be zero.\nCache information are available when a cache system is set.\n\n## Cache system\n\nYou can set a cache for request by adding in the config the `guzzlehttp_cache` with `service` subkey who is a reference\n to a service implementing `M6Web\\Bundle\\GuzzleHttpBundle\\Cache\\CacheInterface`\n\n```yaml\n# app/config/config.yml\nm6web_guzzlehttp:\n    clients:\n        default:\n            base_uri: \"http://domain.tld/\"\n            guzzlehttp_cache:\n                service: my_cache_service\n```\n\nWe provide an \"In memory\" cache class that you can use by defining a new cache service and use it in Guzzle configuration:\n\n```yaml\n# app/config/config.yml\nservices:\n    company.guzzle.cache.inmemory:\n        class: M6Web\\Bundle\\GuzzleHttpBundle\\Cache\\InMemory\n\nm6web_guzzlehttp:\n    clients:\n        default:\n            guzzlehttp_cache:\n                service: company.guzzle.cache.inmemory\n```\n\nWe also provide a cache interface for Redis with [our RedisBundle](https://github.com/M6Web/RedisBundle) \u003e= 2.4, than you can use in this way:\n\n```yaml\n# app/config/config.yml\nm6web_guzzlehttp:\n    clients:\n        default:\n            base_uri: \"http://domain.tld/\"\n            guzzlehttp_cache:\n                service: m6_redis.guzzlehttp\n\nm6_redis:\n    servers:\n        default:\n            ip:   '127.0.0.1'\n            port: 6379\n    clients:\n        guzzlehttp:\n            servers:   [\"default\"]     # list of servers to use\n            namespace: GuzzleHttp\\\n            timeout:   2               # timeout in second\n            readwritetimeout: 2        # read-write timeout in second\n            class: M6Web\\Bundle\\RedisBundle\\CacheAdapters\\M6WebGuzzleHttp\n\n```\n\nFor more information on how to set up the RedisBundle, refer to the README in the project.\n\nWe provide also the same cache system for APCU through the [ApcuBundle](https://github.com/M6Web/ApcuBundle).\n\n## Configuration reference\n\nAs some configuration options accept multiples data types, all services references must start with a `@` character.\n\n```yaml\nm6web_guzzlehttp:\n    clients_share_the_same_handler: false          # Use \"true\" if you want all your clients to share the same Guzzle handler. It means that your different clients will be able to send asynchronous requests altogether.\n    clients:\n        default:\n            base_uri: \"\"                           # Base uri to prepend on request uri\n            timeout: 5.0                           # request timeout\n            http_errors: true                      # Use \"false\" to disable throwing exceptions on HTTP protocol errors\n            redirect_handler: curl                 # guzzle or curl\n            guzzlehttp_cache:                      # optional cache\n                cache_server_errors: true          # at false, no server errors will be cached\n                cache_client_errors: true          # at false, no client errors will be cached\n                default_ttl: 3600                  # default ttl for cache entry in seconds\n                ignore_cache_errors: false         # if true, no exception would be thrown when cache is unavailable\n                use_header_ttl: false              # use the cache-control header to set the ttl\n                service: '@my_cache_service'       # reference to service who implements the cache interface\n            headers:                               # optional. Default request headers\n                User_Agent: \"m6web/1.0\"            # set header \"User-Agent\" with the value \"m6web/1.0\"\n                header\\_name: \"my value\"           # set header \"header_name\" with value \"my value\"\n            auth: [\"user\", \"password\"]             # optional, http auth user and password\n            allow_redirects:                       # false to disallow redirection or an array describing the redirect behavior of a request\n                max: 5                             # Maximum redirect to follow\n                strict: false                      # use \"strict\" RFC compliant redirects. (guzzle redirect handler only)\n                referer: true                      # add a Referer header\n                protocols: ['http', 'https']       # restrict redirect to a protocol\n            body: '@my.body.service'               # string | service reference, request body\n            cert: ['/path/to/.pem', 'password']    # string | array, Set to a string to specify client side certificate, an array if a password is required\n            cookies:                               # boolean | array, false disable cookies\n                -\n                    name: \"bar\"\n                    value: \"foo\"\n                    domain: \"foobar.com\"\n                    path: \"/my/path\"\n                    max: 100\n                    expires: null\n                    secure: false\n                    discard: false\n                    httpOnly: false\n                    max-age: null\n                -\n                    name: tracker\n                    value: tracker\n            connect_timeout: 1                     # float, Float describing the number of seconds to wait while trying to connect to a server\n            debug: true                            # boolean, Set to true to enable debug output with the handler used to send a request\n            decode_content: true                   # string | boolean, specify whether Content-Encoding responses are automatically decoded\n            delay: 10                              # boolean | float, the number of milliseconds to delay before sending the request\n            expect: true                           # boolean | integer, controls the behavior of the \"Expect: 100-Continue\" header\n            force_ip_resolve:                      # Set to \"v4\" if you want the HTTP handlers to use only ipv4 protocol or \"v6\" for ipv6 protocol.\n            form_params:                           # array, Used to send an application/x-www-form-urlencoded POST request.\n                foo: 'bar'\n                bar: 'foo'\n            json: [ foo: 'bar' ]                   # mixed, the json option is used to easily upload JSON encoded data as the body of a request\n            multipart:                             # array, Sets the body of the request to a multipart/form-data form.\n                -\n                    name: 'foo'\n                    contents: 'bar'\n                    headers:\n                        X-foo: 'bar'\n                        X-bar: 'foo'\n            on_headers: '@invokable.service.id'    # A callable that is invoked when the HTTP headers of the response have been received\n            on_stats: '@invokable.service.id'      # on_stats allows you to get access to transfer statistics\n            proxy:                                 # string | array, Pass a string to specify an HTTP proxy, or an array to specify different proxies for different protocols.\n                http: 'tcp://localhost:8125'\n            query:                                 # array, Associative array of query string values or query string to add to the request.\n                foo: 'bar'\n                bar: 'foo'\n            sink: '/path/to/file'                  # String or Psr\\Http\\Message\\StreamInterface service, Specify where the body of a response will be saved.\n            ssl_key: ['/path/to/.pem', 'password'] # string | array, Specify the path to a file containing a private SSL key in PEM format.\n            stream: true                           # Boolean, Set to true to stream a response rather than download it all up-front.\n            synchronous: true                      # Boolean, Set to true to inform HTTP handlers that you intend on waiting on the response. This can be useful for optimizations.\n            verify: true                           # Boolean Describes the SSL certificate verification behavior of a request.\n            version: 1.0                           # String Protocol version to use with the request.\n\n        otherclient:\n            ...\n```\n\nFor the `headers` options, the key in array represent the header name. The underscore will be transformed to hyphen except if it's escaped by a backslash.\n\n## Adding a middleware\n\nImplement `M6Web\\Bundle\\GuzzleHttpBundle\\Middleware\\MiddlewareInterface`.\n\nTag your service with `m6web_guzzlehttp.middleware` and specify the client as follows: \n\n```\nAcme\\Infra\\GraphQL\\Client\\MyMiddleware:\n        tags:\n            - {name: 'm6web_guzzlehttp.middleware', client: 'myclient' }\n``` \n\n## Contributing\n\nFirst, thank you for contributing!\n\nHere are few rules to follow for an easier code review before the maintainers accept and merge your pull request:\n\n- you MUST write or update tests\n- you MUST write or update documentation\n- the CI must pass on your pull request\n\n## Running the test\n\nInstall the composer dev dependencies\n\n```shell\nmake install\n```\n\nThen run the test with [atoum](https://github.com/atoum/atoum) unit test framework\n\n```shell\nmake test\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbedrockstreaming%2Fguzzlehttpbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbedrockstreaming%2Fguzzlehttpbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbedrockstreaming%2Fguzzlehttpbundle/lists"}