{"id":30508269,"url":"https://github.com/aymdev/apiclientbundle","last_synced_at":"2025-08-25T22:17:50.700Z","repository":{"id":310665852,"uuid":"1040589795","full_name":"AymDev/ApiClientBundle","owner":"AymDev","description":"Symfony bundle extending the HttpClient component with extra features (authentication, caching, DTOs, ...)","archived":false,"fork":false,"pushed_at":"2025-08-19T09:50:28.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-08-19T15:15:49.555Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/AymDev.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-08-19T07:59:22.000Z","updated_at":"2025-08-19T13:39:00.000Z","dependencies_parsed_at":"2025-08-19T15:15:57.719Z","dependency_job_id":"d1277264-dbd9-423f-8220-17328c55aaa9","html_url":"https://github.com/AymDev/ApiClientBundle","commit_stats":null,"previous_names":["aymdev/apiclientbundle"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/AymDev/ApiClientBundle","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AymDev%2FApiClientBundle","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AymDev%2FApiClientBundle/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AymDev%2FApiClientBundle/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AymDev%2FApiClientBundle/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/AymDev","download_url":"https://codeload.github.com/AymDev/ApiClientBundle/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/AymDev%2FApiClientBundle/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":272140366,"owners_count":24880502,"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","status":"online","status_checked_at":"2025-08-25T02:00:12.092Z","response_time":1107,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-08-25T22:17:47.321Z","updated_at":"2025-08-25T22:17:50.693Z","avatar_url":"https://github.com/AymDev.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# API Client Bundle\nA **PHP 8.3+** \u0026 **Symfony 5 / 6 / 7** bundle extending the **Symfony HttpClient** component with extra features: authentication, caching, DTOs, ...\n\n![Testing](https://github.com/AymDev/ApiClientBundle/workflows/Testing/badge.svg)\n![Coding Standards](https://github.com/AymDev/ApiClientBundle/workflows/Coding%20Standards/badge.svg)\n![Bundle installation](https://github.com/AymDev/ApiClientBundle/workflows/Bundle%20installation/badge.svg)\n[![Latest Stable Version](https://poser.pugx.org/aymdev/api-client-bundle/v)](//packagist.org/packages/aymdev/api-client-bundle)\n[![License](https://poser.pugx.org/aymdev/api-client-bundle/license)](//packagist.org/packages/aymdev/api-client-bundle)\n\n\u003eThis bundle is a *work in progress* and should get a stable release soon.\n\n# Why this bundle\n\nThe **Symfony HttpClient** component is a very powerful component but you can write the same code over and over if you\nwant to make it work with authentication, DTOs, caching, etc.\n\nThis bundle extends the **HttpClient** component and offers features through the `user_data` option key in your requests.\nAll you need to know are the features described in this documentation and the official\n[HttpClient documentation](https://symfony.com/doc/current/http_client.html) !\n\n# Usage\n\nInstall the bundle with **Composer**:\n```shell\ncomposer require aymdev/api-client-bundle\n```\n\nConfigure it depending on the features you want to use by creating a **aymdev_api_client.yaml** file:\n```yaml\naymdev_api_client:\n    # enable features\n```\n\nFetch the service using the `AymDev\\ApiClientBundle\\Client\\ApiClientInterface` and use its constants in the `user_data`\noptions of your requests:\n\n```php\n\u003c?php\n\ndeclare(strict_types=1);\n\nnamespace App;\n\nuse AymDev\\ApiClientBundle\\Client\\ApiClientInterface;\nuse Symfony\\Contracts\\HttpClient\\ResponseInterface;\n\nclass MyService\n{\n    public function __construct(\n        private readonly ApiClientInterface $apiClient,\n    ) {\n    }\n    \n    public function apiCall(): ResponseInterface\n    {\n        return $this-\u003eapiClient-\u003erequest('GET', 'https://example.com', [\n            'user_data' =\u003e [\n                ApiClientInterface::REQUEST_ID =\u003e 'api.example_com.unique_id',\n            ],\n        ]);\n    }\n}\n```\n\n# Request ID\n\nMultiple features will need you to define a *request ID* identifying the HTTP calls. This can then be used to create a\ncache key, log the correct response when doing concurrent requests, etc.\n\nYour *request ID* must be unique to the call and is defined with the `REQUEST_ID` constant:\n```php\nuse AymDev\\ApiClientBundle\\Client\\ApiClientInterface;\n\n// ... \n\npublic function getOne(int $id): ResponseInterface\n{\n    return $this-\u003eapiClient-\u003erequest('GET', 'https://api.com/item', [\n        'query' =\u003e [\n            'id' =\u003e $id,\n        ],\n        'user_data' =\u003e [\n            // Note that the \"dynamic property\" is part of the request ID\n            ApiClientInterface::REQUEST_ID =\u003e 'api_com.item.' . $id,\n        ]\n    ]);\n}\n```\n\n# Logging\n\nYou can enable detailed logging by providing a **PSR logger** service:\n```yaml\naymdev_api_client:\n    logger: my.psr.logger.service\n```\n\nThen it will log any call with a defined *request ID* with the following properties:\n\n| Key               | Description                                     |\n|-------------------|-------------------------------------------------|\n| `method`          | HTTP method                                     |\n| `url`             | URL endpoint                                    |\n| `request_body`    | (optional) HTTP request body                    |\n| `response_status` | HTTP status code of the response                |\n| `response_body`   | (optional) HTTP response body                   |\n| `time`            | duration of the request (in seconds)            |\n| `cache`           | if the response has been fetched from the cache |\n| `error`           | error message if anything occured               |\n\n## Request/Response body logging\n\nYou can enable logging of the request and response body setting dedicated constants to `true`:\n\n - `LOG_REQUEST_BODY`: logs the request body (works with plain strings only)\n - `LOG_RESPONSE_BODY`: logs the response body\n - `LOG_ERROR_RESPONSE_BODY`: logs the response body only if the response status is \u003e=300\n\n# Cache\n\nYou can save responses in cache by providing a **PSR cache pool** service:\n```yaml\naymdev_api_client:\n    cache: my.psr.cache.service\n```\n\nThen you can enable caching per request using the following constants:\n\n - `CACHE_DURATION`: number of seconds to keep in cache\n - `CACHE_EXPIRATION`: expiration time of the response (overrides `CACHE_DURATION`)\n - `CACHE_ERROR_DURATION`: same as `CACHE_DURATION` but will be applied if the response status is \u003e=300\n\nThe cache key will be determined based on the *request ID*:\n```php\nuse AymDev\\ApiClientBundle\\Client\\ApiClientInterface;\n\n$apiClient-\u003erequest('GET', 'https://example.com', [\n    'user_data' =\u003e [\n        ApiClientInterface::REQUEST_ID =\u003e 'my.request.id',\n        \n        // You actually need to define only one of those options\n        ApiClientInterface::CACHE_DURATION =\u003e 86400,\n        ApiClientInterface::CACHE_EXPIRATION =\u003e new \\DateTime('Tomorrow 6 am'),\n        \n        // Will override previous options if an error occurs\n        ApiClientInterface::CACHE_ERROR_DURATION =\u003e 3600,\n    ]\n]);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymdev%2Fapiclientbundle","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faymdev%2Fapiclientbundle","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faymdev%2Fapiclientbundle/lists"}