{"id":19432042,"url":"https://github.com/guzzle/command","last_synced_at":"2025-05-15T11:00:22.202Z","repository":{"id":14450374,"uuid":"17162016","full_name":"guzzle/command","owner":"guzzle","description":"Provides the foundation for building web service clients with Guzzle","archived":false,"fork":false,"pushed_at":"2025-02-04T09:57:53.000Z","size":361,"stargazers_count":115,"open_issues_count":0,"forks_count":21,"subscribers_count":13,"default_branch":"1.3","last_synced_at":"2025-04-10T06:32:13.496Z","etag":null,"topics":["guzzle","guzzle-services","middleware","promises"],"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/guzzle.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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},"funding":{"github":["Nyholm","GrahamCampbell"],"tidelift":"packagist/guzzlehttp/command"}},"created_at":"2014-02-25T05:03:07.000Z","updated_at":"2025-02-07T12:33:35.000Z","dependencies_parsed_at":"2025-02-12T17:11:10.506Z","dependency_job_id":"5c5cb595-0644-48dd-a84a-3c863c9f4722","html_url":"https://github.com/guzzle/command","commit_stats":{"total_commits":149,"total_committers":14,"mean_commits":"10.642857142857142","dds":"0.25503355704697983","last_synced_commit":"3c9383aaf2e39fa8d39375ae37b95b55964aaef4"},"previous_names":[],"tags_count":19,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzzle%2Fcommand","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzzle%2Fcommand/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzzle%2Fcommand/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guzzle%2Fcommand/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guzzle","download_url":"https://codeload.github.com/guzzle/command/tar.gz/refs/heads/1.3","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254328384,"owners_count":22052632,"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":["guzzle","guzzle-services","middleware","promises"],"created_at":"2024-11-10T14:33:51.462Z","updated_at":"2025-05-15T11:00:22.176Z","avatar_url":"https://github.com/guzzle.png","language":"PHP","funding_links":["https://github.com/sponsors/Nyholm","https://github.com/sponsors/GrahamCampbell","https://tidelift.com/funding/github/packagist/guzzlehttp/command","https://tidelift.com/subscription/pkg/packagist-guzzlehttp-command?utm_source=packagist-guzzlehttp-command\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo"],"categories":[],"sub_categories":[],"readme":"# Guzzle Commands\n\nThis library uses Guzzle and provides the foundations to create fully-featured\nweb service clients by abstracting Guzzle HTTP *requests* and *responses* into\nhigher-level *commands* and *results*. A *middleware* system, analogous to, but\nseparate from, the one in the HTTP layer may be used to customize client\nbehavior when preparing commands into requests and processing responses into\nresults.\n\n### Commands\n\nKey-value pair objects representing an operation of a web service. Commands\nhave a name and a set of parameters.\n\n### Results\n\nKey-value pair objects representing the processed result of executing an\noperation of a web service.\n\n## Installing\n\nThis project can be installed using [Composer](https://getcomposer.org/):\n\n```\ncomposer require guzzlehttp/command\n```\n\n## Service Clients\n\nService Clients are web service clients that implement the\n`GuzzleHttp\\Command\\ServiceClientInterface` and use an underlying Guzzle HTTP\nclient (`GuzzleHttp\\ClientInterface`) to communicate with the service. Service\nclients create and execute *commands* (`GuzzleHttp\\Command\\CommandInterface`),\nwhich encapsulate operations within the web service, including the operation\nname and parameters. This library provides a generic implementation of a service\nclient: the `GuzzleHttp\\Command\\ServiceClient` class.\n\n## Instantiating a Service Client\n\nThe provided service client implementation (`GuzzleHttp\\Command\\ServiceClient`)\ncan be instantiated by providing the following arguments:\n\n1. A fully-configured Guzzle HTTP client that will be used to perform the\n   underlying HTTP requests. That is, an instance of an object implementing\n   `GuzzleHttp\\ClientInterface` such as `new GuzzleHttp\\Client()`.\n1. A callable that transforms a Command into a Request. The function should\n   accept a `GuzzleHttp\\Command\\CommandInterface` object and return a\n   `Psr\\Http\\Message\\RequestInterface` object.\n1. A callable that transforms a Response into a Result. The function should\n   accept a `Psr\\Http\\Message\\ResponseInterface` object and optionally a\n   `Psr\\Http\\Message\\RequestInterface` object, and return a\n   `GuzzleHttp\\Command\\ResultInterface` object.\n1. Optionally, a Guzzle HandlerStack (`GuzzleHttp\\HandlerStack`), which can be\n   used to add command-level middleware to the service client.\n\nBelow is an example configured to send and receive JSON payloads:\n\n```php\nuse GuzzleHttp\\Command\\CommandInterface;\nuse GuzzleHttp\\Command\\Result;\nuse GuzzleHttp\\Command\\ResultInterface;\nuse GuzzleHttp\\Command\\ServiceClient;\nuse GuzzleHttp\\Psr7\\Request;\nuse GuzzleHttp\\UriTemplate\\UriTemplate;\nuse GuzzleHttp\\Utils;\nuse Psr\\Http\\Message\\RequestInterface;\nuse Psr\\Http\\Message\\ResponseInterface;\n\n$client = new ServiceClient(\n    new HttpClient(),\n    function (CommandInterface $command): RequestInterface {\n        return new Request(\n            'POST',\n            UriTemplate::expand('/{command}', ['command' =\u003e $command-\u003egetName()]),\n            ['Accept' =\u003e 'application/json', 'Content-Type' =\u003e 'application/json'],\n            Utils::jsonEncode($command-\u003etoArray())\n        );\n    },\n    function (ResponseInterface $response, RequestInterface $request): ResultInterface {\n        return new Result(\n            Utils::jsonDecode((string) $response-\u003egetBody(), true)\n        );\n    }\n);\n```\n\n## Executing Commands\n\nService clients create command objects using the ``getCommand()`` method.\n\n```php\n$commandName = 'foo';\n$arguments = ['baz' =\u003e 'bar'];\n$command = $client-\u003egetCommand($commandName, $arguments);\n```\n\nAfter creating a command, you may execute the command using the `execute()`\nmethod of the client.\n\n```php\n$result = $client-\u003eexecute($command);\n```\n\nThe result of executing a command will be an instance of an object implementing\n`GuzzleHttp\\Command\\ResultInterface`. Result objects are `ArrayAccess`-ible and\ncontain the data parsed from HTTP response.\n\nService clients have magic methods that act as shortcuts to executing commands\nby name without having to create the ``Command`` object in a separate step\nbefore executing it.\n\n```php\n$result = $client-\u003efoo(['baz' =\u003e 'bar']);\n```\n\n## Asynchronous Commands\n\n@TODO Add documentation\n\n* ``-Async`` suffix for client methods\n* Promises\n\n```php\n// Create and execute an asynchronous command.\n$command = $command = $client-\u003egetCommand('foo', ['baz' =\u003e 'bar']);\n$promise = $client-\u003eexecuteAsync($command);\n\n// Use asynchronous commands with magic methods.\n$promise = $client-\u003efooAsync(['baz' =\u003e 'bar']);\n```\n\n@TODO Add documentation\n\n* ``wait()``-ing on promises.\n\n```php\n$result = $promise-\u003ewait();\n\necho $result['fizz']; //\u003e 'buzz'\n```\n\n## Concurrent Requests\n\n@TODO Add documentation\n\n* ``executeAll()``\n* ``executeAllAsync()``.\n* Options (``fulfilled``, ``rejected``, ``concurrency``)\n\n## Middleware: Extending the Client\n\nMiddleware can be added to the service client or underlying HTTP client to\nimplement additional behavior and customize the ``Command``-to-``Result`` and\n``Request``-to-``Response`` lifecycles, respectively.\n\n## Security\n\nIf you discover a security vulnerability within this package, please send an email to security@tidelift.com. All security vulnerabilities will be promptly addressed. Please do not disclose security-related issues publicly until a fix has been announced. Please see [Security Policy](https://github.com/guzzle/command/security/policy) for more information.\n\n## License\n\nGuzzle is made available under the MIT License (MIT). Please see [License File](LICENSE) for more information.\n\n## For Enterprise\n\nAvailable as part of the Tidelift Subscription\n\nThe maintainers of Guzzle and thousands of other packages are working with Tidelift to deliver commercial support and maintenance for the open source dependencies you use to build your applications. Save time, reduce risk, and improve code health, while paying the maintainers of the exact dependencies you use. [Learn more.](https://tidelift.com/subscription/pkg/packagist-guzzlehttp-command?utm_source=packagist-guzzlehttp-command\u0026utm_medium=referral\u0026utm_campaign=enterprise\u0026utm_term=repo)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzzle%2Fcommand","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguzzle%2Fcommand","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguzzle%2Fcommand/lists"}