{"id":18941220,"url":"https://github.com/reactphp/http-client","last_synced_at":"2025-05-16T04:06:29.138Z","repository":{"id":450316,"uuid":"6432321","full_name":"reactphp/http-client","owner":"reactphp","description":"[Deprecated] Event-driven, streaming HTTP client for ReactPHP.","archived":false,"fork":false,"pushed_at":"2022-06-20T14:20:05.000Z","size":181,"stargazers_count":230,"open_issues_count":1,"forks_count":65,"subscribers_count":20,"default_branch":"master","last_synced_at":"2024-04-13T16:33:41.169Z","etag":null,"topics":["http","http-client","php","reactphp"],"latest_commit_sha":null,"homepage":"https://reactphp.org/http-client/","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/reactphp.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}},"created_at":"2012-10-28T21:33:00.000Z","updated_at":"2024-03-18T13:50:24.000Z","dependencies_parsed_at":"2022-07-07T23:38:42.191Z","dependency_job_id":null,"html_url":"https://github.com/reactphp/http-client","commit_stats":null,"previous_names":[],"tags_count":37,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fhttp-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fhttp-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fhttp-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactphp%2Fhttp-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactphp","download_url":"https://codeload.github.com/reactphp/http-client/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247175467,"owners_count":20896294,"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","http-client","php","reactphp"],"created_at":"2024-11-08T12:26:45.608Z","updated_at":"2025-04-08T14:11:18.599Z","avatar_url":"https://github.com/reactphp.png","language":"PHP","readme":"# Deprecation notice\n\nThis package has now been migrated over to\n[react/http](https://github.com/reactphp/http)\nand only exists for BC reasons.\n\n```bash\n$ composer require react/http\n```\n\nIf you've previously used this package, upgrading may take a moment or two.\nThe new API has been updated to use Promises and PSR-7 message abstractions.\nThis means it's now more powerful and easier to use than ever:\n\n```php\n// old\n$client = new React\\HttpClient\\Client($loop);\n$request = $client-\u003erequest('GET', 'https://example.com/');\n$request-\u003eon('response', function ($response) {\n    $response-\u003eon('data', function ($chunk) {\n        echo $chunk;\n    });\n});\n$request-\u003eend();\n\n// new\n$browser = new React\\Http\\Browser($loop);\n$browser-\u003eget('https://example.com/')-\u003ethen(function (Psr\\Http\\Message\\ResponseInterface $response) {\n    echo $response-\u003egetBody();\n});\n```\n\nSee [react/http](https://github.com/reactphp/http#client-usage) for more details.\n\nThe below documentation applies to the last release of this package.\nFurther development will take place in the updated\n[react/http](https://github.com/reactphp/http),\nso you're highly recommended to upgrade as soon as possible.\n\n# Deprecated HttpClient\n\n[![Build Status](https://travis-ci.org/reactphp/http-client.svg?branch=master)](https://travis-ci.org/reactphp/http-client)\n\nEvent-driven, streaming HTTP client for [ReactPHP](https://reactphp.org).\n\n**Table of Contents**\n\n* [Basic usage](#basic-usage)\n  * [Client](#client)\n  * [Example](#example)\n* [Advanced usage](#advanced-usage)\n  * [Unix domain sockets](#unix-domain-sockets)\n* [Install](#install)\n* [Tests](#tests)\n* [License](#license)\n\n## Basic usage\n\n### Client\n\nThe `Client` is responsible for communicating with HTTP servers, managing the\nconnection state and sending your HTTP requests.\nIt also registers everything with the main [`EventLoop`](https://github.com/reactphp/event-loop#usage).\n\n```php\n$loop = React\\EventLoop\\Factory::create();\n$client = new Client($loop);\n```\n\nIf you need custom connector settings (DNS resolution, TLS parameters, timeouts,\nproxy servers etc.), you can explicitly pass a custom instance of the\n[`ConnectorInterface`](https://github.com/reactphp/socket#connectorinterface):\n\n```php\n$connector = new \\React\\Socket\\Connector($loop, array(\n    'dns' =\u003e '127.0.0.1',\n    'tcp' =\u003e array(\n        'bindto' =\u003e '192.168.10.1:0'\n    ),\n    'tls' =\u003e array(\n        'verify_peer' =\u003e false,\n        'verify_peer_name' =\u003e false\n    )\n));\n\n$client = new Client($loop, $connector);\n```\n\nThe `request(string $method, string $uri, array $headers = array(), string $version = '1.0'): Request`\nmethod can be used to prepare new Request objects.\n\nThe optional `$headers` parameter can be used to pass additional request\nheaders.\nYou can use an associative array (key=value) or an array for each header value\n(key=values).\nThe Request will automatically include an appropriate `Host`,\n`User-Agent: react/alpha` and `Connection: close` header if applicable.\nYou can pass custom header values or use an empty array to omit any of these.\n\nThe `Request#write(string $data)` method can be used to\nwrite data to the request body.\nData will be buffered until the underlying connection is established, at which\npoint buffered data will be sent and all further data will be passed to the\nunderlying connection immediately.\n\nThe `Request#end(?string $data = null)` method can be used to\nfinish sending the request.\nYou may optionally pass a last request body data chunk that will be sent just\nlike a `write()` call.\nCalling this method finalizes the outgoing request body (which may be empty).\nData will be buffered until the underlying connection is established, at which\npoint buffered data will be sent and all further data will be ignored.\n\nThe `Request#close()` method can be used to\nforefully close sending the request.\nUnlike the `end()` method, this method discards any buffers and closes the\nunderlying connection if it is already established or cancels the pending\nconnection attempt otherwise.\n\nRequest implements WritableStreamInterface, so a Stream can be piped to it.\nInteresting events emitted by Request:\n\n* `response`: The response headers were received from the server and successfully\n  parsed. The first argument is a Response instance.\n* `drain`: The outgoing buffer drained and the response is ready to accept more\n  data for the next `write()` call.\n* `error`: An error occurred, an `Exception` is passed as first argument.\n  If the response emits an `error` event, this will also be emitted here.\n* `close`: The request is closed. If an error occurred, this event will be\n  preceeded by an `error` event.\n  For a successful response, this will be emitted only once the response emits\n  the `close` event.\n\nResponse implements ReadableStreamInterface.\nInteresting events emitted by Response:\n\n* `data`: Passes a chunk of the response body as first argument.\n  When a response encounters a chunked encoded response it will parse it\n  transparently for the user and removing the `Transfer-Encoding` header.\n* `error`: An error occurred, an `Exception` is passed as first argument.\n  This will also be forwarded to the request and emit an `error` event there.\n* `end`: The response has been fully received.\n* `close`: The response is closed. If an error occured, this event will be\n  preceeded by an `error` event.\n  This will also be forwarded to the request and emit a `close` event there.\n\n### Example\n\n```php\n\u003c?php\n\n$loop = React\\EventLoop\\Factory::create();\n$client = new React\\HttpClient\\Client($loop);\n\n$request = $client-\u003erequest('GET', 'https://github.com/');\n$request-\u003eon('response', function ($response) {\n    $response-\u003eon('data', function ($chunk) {\n        echo $chunk;\n    });\n    $response-\u003eon('end', function() {\n        echo 'DONE';\n    });\n});\n$request-\u003eon('error', function (\\Exception $e) {\n    echo $e;\n});\n$request-\u003eend();\n$loop-\u003erun();\n```\n\nSee also the [examples](examples).\n\n## Advanced Usage\n\n### Unix domain sockets\n\nBy default, this library supports transport over plaintext TCP/IP and secure\nTLS connections for the `http://` and `https://` URI schemes respectively.\nThis library also supports Unix domain sockets (UDS) when explicitly configured.\n\nIn order to use a UDS path, you have to explicitly configure the connector to\noverride the destination URI so that the hostname given in the request URI will\nno longer be used to establish the connection:\n\n```php\n$connector = new FixedUriConnector(\n    'unix:///var/run/docker.sock',\n    new UnixConnector($loop)\n);\n\n$client = new Client($loop, $connector);\n\n$request = $client-\u003erequest('GET', 'http://localhost/info');\n```\n\nSee also [example #11](examples/11-unix-domain-sockets.php).\n\n## Install\n\nThe recommended way to install this library is [through Composer](https://getcomposer.org).\n[New to Composer?](https://getcomposer.org/doc/00-intro.md)\n\nThis will install the latest supported version:\n\n```bash\n$ composer require react/http-client:^0.5.10\n```\n\nSee also the [CHANGELOG](CHANGELOG.md) for details about version upgrades.\n\nThis project aims to run on any platform and thus does not require any PHP\nextensions and supports running on legacy PHP 5.3 through current PHP 7+ and\nHHVM.\nIt's *highly recommended to use PHP 7+* for this project.\n\n## Tests\n\nTo run the test suite, you first need to clone this repo and then install all\ndependencies [through Composer](https://getcomposer.org):\n\n```bash\n$ composer install\n```\n\nTo run the test suite, go to the project root and run:\n\n```bash\n$ php vendor/bin/phpunit\n```\n\nThe test suite also contains a number of functional integration tests that send\ntest HTTP requests against the online service http://httpbin.org and thus rely\non a stable internet connection.\nIf you do not want to run these, they can simply be skipped like this:\n\n```bash\n$ php vendor/bin/phpunit --exclude-group internet\n```\n\n## License\n\nMIT, see [LICENSE file](LICENSE).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactphp%2Fhttp-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactphp%2Fhttp-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactphp%2Fhttp-client/lists"}