{"id":20980629,"url":"https://github.com/php-api-clients/transport","last_synced_at":"2025-05-14T15:30:48.371Z","repository":{"id":52422267,"uuid":"70328375","full_name":"php-api-clients/transport","owner":"php-api-clients","description":":rocket: API Client Transport for PHP 7.x","archived":false,"fork":false,"pushed_at":"2023-12-15T05:08:09.000Z","size":435,"stargazers_count":4,"open_issues_count":4,"forks_count":3,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-04-22T14:57:38.139Z","etag":null,"topics":["api-client","hacktoberfest","middleware","php","php7","reactphp","transport"],"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/php-api-clients.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","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}},"created_at":"2016-10-08T12:02:25.000Z","updated_at":"2022-02-12T10:51:09.000Z","dependencies_parsed_at":"2023-12-15T06:46:07.974Z","dependency_job_id":null,"html_url":"https://github.com/php-api-clients/transport","commit_stats":{"total_commits":327,"total_committers":7,"mean_commits":"46.714285714285715","dds":0.07033639143730885,"last_synced_commit":"1d02fb88b51355c92874bee5492b6d47801fa54f"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Ftransport","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Ftransport/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Ftransport/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/php-api-clients%2Ftransport/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/php-api-clients","download_url":"https://codeload.github.com/php-api-clients/transport/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254171586,"owners_count":22026467,"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":["api-client","hacktoberfest","middleware","php","php7","reactphp","transport"],"created_at":"2024-11-19T05:29:24.375Z","updated_at":"2025-05-14T15:30:46.058Z","avatar_url":"https://github.com/php-api-clients.png","language":"PHP","readme":"# API Client Transport for PHP 7.x\n\n[![Build Status](https://travis-ci.org/php-api-clients/transport.svg?branch=master)](https://travis-ci.org/php-api-clients/transport)\n[![Latest Stable Version](https://poser.pugx.org/api-clients/transport/v/stable.png)](https://packagist.org/packages/api-clients/transport)\n[![Total Downloads](https://poser.pugx.org/api-clients/transport/downloads.png)](https://packagist.org/packages/api-clients/transport/stats)\n[![Code Coverage](https://scrutinizer-ci.com/g/php-api-clients/transport/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/php-api-clients/transport/?branch=master)\n[![License](https://poser.pugx.org/api-clients/transport/license.png)](https://packagist.org/packages/api-clients/transport)\n[![PHP 7 ready](http://php7ready.timesplinter.ch/php-api-clients/transport/badge.svg)](https://appveyor-ci.org/php-api-clients/transport)\n\nIn a nutshell this package is a wrapper around `clue/buzz-react` adding [middleware](https://github.com/php-api-clients/middleware).\n\n# Install\n\nTo install via [Composer](http://getcomposer.org/), use the command below, it will automatically detect the latest version and bind it with `^`.\n\n```\ncomposer require api-clients/transport\n```\n\n# Usage\n\nCreating the client can be done using the factory:\n\n```php\n$locator = new MiddlewareLocator(); // A concrete class implementing the middleware locator interface \n$loop = EventLoopFactory::create(); // The event loop\n$options = []; // Client options, as described below\n$client = Factory::create($locator, $loop, $options);\n```\n\nNext you can make PSR-7 request:\n\n```php\n$request = new PsrRequest(); // \n$requestOptions = []; // Options such as middleware settings\n$client-\u003erequest($request, $requestOptions)-\u003edone(function (ResponseInterface $response) {\n    // Handle the response\n});\n```\n\n# Middleware\n\nMiddlewares are passed into the client with the options argument. In this example the [`api-clients/middleware-delay`](https://github.com/php-api-clients/middleware-delay) is used. Adding middlewares to the client is simple, add an array to `$options` with `Options::MIDDLEWARE` as index cosisting of middleware class names. Optionally you can pass options for the middleware through the `$options` array. Simply add a new array inside the array with the middlware class name as index and pass the desired options into it.\n\n```php\n$options = [\n    Options::DEFAULT_REQUEST_OPTIONS =\u003e [\n        \\ApiClients\\Middleware\\Delay\\DelayMiddleware::class =\u003e [\n            \\ApiClients\\Middleware\\Delay\\Options::DELAY =\u003e 3,\n        ],\n    ],\n    Options::MIDDLEWARE =\u003e [\n        \\ApiClients\\Middleware\\Delay\\DelayMiddleware::class,\n    ],\n];\n\n$client = new Client($loop, $container, $browser, $options);\n```\n\nMiddleware options can be changed per request, this specific request only will have a delay of 5 seconds instead of the default 3:\n\n```php\n$requestOptions = [\n    \\ApiClients\\Middleware\\Delay\\DelayMiddleware::class =\u003e [\n        \\ApiClients\\Middleware\\Delay\\Options::DELAY =\u003e 5,\n    ],\n];\n$client-\u003erequest($request, $requestOptions);\n```\n\n# Options\n\n## Options::DNS\n\nDNS server to use resolving hostnames, defaults to `8.8.8.8`. \n\n## Options::SCHEMA\n\nSchema part of the URI, defaults to `https`. \n\n## Options::HOST\n\nHost part of the URI, required. \n\n## Options::PORT\n\nPort part of the URI, optional. \n\n## Options::PATH\n\nPath part of the URI, defaults to `/`. \n\n## Options::HEADERS\n\nKey value array with headers, defaults to `[]`.\n\n## Options::MIDDLEWARE\n\nArray with middleware class names, for example `[MiddlewareOne::class, MiddlewareTwo::class]`, defaults to `[]`.\n\n## Options::DEFAULT_REQUEST_OPTIONS\n\nSet of default request options, mainly useful for middlewares needed for all requests, defaults to `[]`.\n\n# License\n\nThe MIT License (MIT)\n\nCopyright (c) 2017 Cees-Jan Kiewiet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-api-clients%2Ftransport","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphp-api-clients%2Ftransport","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphp-api-clients%2Ftransport/lists"}