{"id":16954629,"url":"https://github.com/tarkhov/guzzle-xml","last_synced_at":"2025-04-11T21:45:17.144Z","repository":{"id":48621183,"uuid":"118229121","full_name":"tarkhov/guzzle-xml","owner":"tarkhov","description":"Guzzle XML request and response.","archived":false,"fork":false,"pushed_at":"2022-01-13T00:27:54.000Z","size":24,"stargazers_count":1,"open_issues_count":5,"forks_count":2,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-25T17:49:25.163Z","etag":null,"topics":["composer","guzzle","php","xml"],"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/tarkhov.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":null,"security":null,"support":null}},"created_at":"2018-01-20T09:33:07.000Z","updated_at":"2021-07-17T11:44:31.000Z","dependencies_parsed_at":"2022-09-15T20:51:27.025Z","dependency_job_id":null,"html_url":"https://github.com/tarkhov/guzzle-xml","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarkhov%2Fguzzle-xml","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarkhov%2Fguzzle-xml/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarkhov%2Fguzzle-xml/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/tarkhov%2Fguzzle-xml/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/tarkhov","download_url":"https://codeload.github.com/tarkhov/guzzle-xml/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248487509,"owners_count":21112187,"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":["composer","guzzle","php","xml"],"created_at":"2024-10-13T22:10:10.859Z","updated_at":"2025-04-11T21:45:17.117Z","avatar_url":"https://github.com/tarkhov.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Guzzle XML\n\nGuzzle XML request and response.\n\n### Contents\n\n1. [Compatibility](#compatibility)\n   1. [Version support](#version-support)\n2. [Installation](#installation)\n   1. [Composer](#composer)\n3. [Usage](#usage)\n   1. [Request options](#request-options)\n   2. [Response](#response)\n4. [Author](#author)\n5. [License](#license)\n\n## Compatibility\n\nLibrary | Version\n------- | -------\nPHP | \u003e=7.2.5\nGuzzle | \u003e=7.0 and \u003c 8.0\nSymfony Serializer | \u003e=5.0 and \u003c 6.0\n\n### Version support\n\nGuzzle | PHP | Repo\n------- | ------- | -------\n6.x | \u003e=5.5 | [0.x](https://github.com/tarkhov/guzzle-xml/tree/0.x)\n7.x | \u003e=7.2 | [1.x](https://github.com/tarkhov/guzzle-xml/tree/1.x)\n\n## Installation\n\n### Composer\n\n```bash\ncomposer require tarkhov/guzzle-xml\n```\n\n## Usage\n\n### Request options\n\nFollowing example creates POST request with XML body. Option `xml` accepts an array that is converted to XML document. About array format and how converting works you can read in detail [Symfony XmlEncoder](https://symfony.com/doc/current/components/serializer.html#the-xmlencoder).\n\n```php\n\u003c?php\nuse GuzzleHttp\\HandlerStack;\nuse GuzzleHttp\\Client;\nuse GuzzleXml\\XmlMiddleware;\n\n$stack = HandlerStack::create();\n$stack-\u003epush(XmlMiddleware::xml(), 'xml');\n$client = new Client(['handler' =\u003e $stack]);\n$response = $client-\u003epost('https://example.com', [\n  'xml' =\u003e [\n    'package' =\u003e [\n        '@language' =\u003e 'PHP',\n        'name'      =\u003e 'Guzzle XML',\n        'author'    =\u003e [\n          '@role' =\u003e 'developer',\n          '#'     =\u003e 'Alexander Tarkhov',\n        ],\n        'support'   =\u003e [\n            'issues' =\u003e 'https://github.com/tarkhov/guzzle-xml/issues',\n            'source' =\u003e 'https://github.com/tarkhov/guzzle-xml',\n        ],\n    ],\n  ],\n]);\n```\n\nAs a result, an xml request will be sent with the header `Content-type: text/xml` and data with the following content:\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cpackage language=\"PHP\"\u003e\n   \u003cname\u003eGuzzle XML\u003c/name\u003e\n   \u003cauthor role=\"developer\"\u003eAlexander Tarkhov\u003c/author\u003e\n   \u003csupport\u003e\n      \u003cissues\u003ehttps://github.com/tarkhov/guzzle-xml/issues\u003c/issues\u003e\n      \u003csource\u003ehttps://github.com/tarkhov/guzzle-xml\u003c/source\u003e\n   \u003c/support\u003e\n\u003c/package\u003e\n```\n\n### Response\n\nAutomatically convert your JSON response to XML using middleware.\n\n```php\n\u003c?php\nuse GuzzleHttp\\HandlerStack;\nuse GuzzleHttp\\Client;\nuse GuzzleXml\\XmlMiddleware;\n\n$stack = HandlerStack::create();\n$stack-\u003epush(XmlMiddleware::jsonToXml());\n$client = new Client(['handler' =\u003e $stack]);\n$response = $client-\u003epost('https://example.com');\n$xml = $response-\u003egetBody();\necho $xml;\n```\n\nIf you json response is:\n\n```json\n{\n   \"package\": {\n      \"@language\":\"PHP\",\n      \"name\":\"Guzzle XML\",\n      \"author\": {\n         \"@role\":\"developer\",\n         \"#\":\"Alexander Tarkhov\"\n      },\n      \"support\": {\n         \"issues\":\"https:\\/\\/github.com\\/tarkhov\\/guzzle-xml\\/issues\",\n         \"source\":\"https:\\/\\/github.com\\/tarkhov\\/guzzle-xml\"\n      }\n   }\n}\n```\n\nThis will automatically convert to XML like this:\n\n```xml\n\u003c?xml version=\"1.0\"?\u003e\n\u003cpackage language=\"PHP\"\u003e\n   \u003cname\u003eGuzzle XML\u003c/name\u003e\n   \u003cauthor role=\"developer\"\u003eAlexander Tarkhov\u003c/author\u003e\n   \u003csupport\u003e\n      \u003cissues\u003ehttps://github.com/tarkhov/guzzle-xml/issues\u003c/issues\u003e\n      \u003csource\u003ehttps://github.com/tarkhov/guzzle-xml\u003c/source\u003e\n   \u003c/support\u003e\n\u003c/package\u003e\n```\n\n## Author\n\n**Alexander Tarkhov**\n\n* [Twitter](https://twitter.com/alextarkhov)\n* [Medium](https://medium.com/@tarkhov)\n* [LinkedIn](https://www.linkedin.com/in/tarkhov/)\n* [Facebook](https://www.facebook.com/alextarkhov)\n\n## License\n\nThis project is licensed under the **MIT License** - see the `LICENSE` file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarkhov%2Fguzzle-xml","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftarkhov%2Fguzzle-xml","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftarkhov%2Fguzzle-xml/lists"}