{"id":20678884,"url":"https://github.com/phpgt/fetch","last_synced_at":"2025-04-23T08:17:44.517Z","repository":{"id":49532955,"uuid":"69451212","full_name":"phpgt/Fetch","owner":"phpgt","description":"Asynchronous HTTP client with promises.","archived":false,"fork":false,"pushed_at":"2025-04-22T13:54:11.000Z","size":395,"stargazers_count":34,"open_issues_count":11,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-23T08:17:37.327Z","etag":null,"topics":["curl","curl-functions","fetch","http","http-client","phpgt","promise","promise-support","promises"],"latest_commit_sha":null,"homepage":"https://www.php.gt/fetch","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/phpgt.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":null,"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":["phpgt"]}},"created_at":"2016-09-28T10:08:31.000Z","updated_at":"2025-04-21T14:01:59.000Z","dependencies_parsed_at":"2024-06-20T00:15:12.148Z","dependency_job_id":"abb3356e-cc69-4105-9bc1-834d3898aef3","html_url":"https://github.com/phpgt/Fetch","commit_stats":{"total_commits":249,"total_committers":6,"mean_commits":41.5,"dds":"0.12048192771084343","last_synced_commit":"d823a306e950ea0538dfd7a54bed30b5aacd6acd"},"previous_names":[],"tags_count":20,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FFetch","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FFetch/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FFetch/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/phpgt%2FFetch/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/phpgt","download_url":"https://codeload.github.com/phpgt/Fetch/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250395289,"owners_count":21423400,"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":["curl","curl-functions","fetch","http","http-client","phpgt","promise","promise-support","promises"],"created_at":"2024-11-16T21:22:55.616Z","updated_at":"2025-04-23T08:17:44.500Z","avatar_url":"https://github.com/phpgt.png","language":"PHP","readme":"# Asynchronous HTTP client with promises.\n\nAsynchronous HTTP client, implementation of the [Fetch Standard][fetch-standard] which defines requests, responses, and the process that binds them: _fetching_.\n\nSee also, the [JavaScript implementation][fetch-js] that ships as standard in all modern browsers.\n\n***\n\n\u003ca href=\"https://github.com/PhpGt/Fetch/actions\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.status.php.gt/fetch-build.svg\" alt=\"Build status\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codacy.com/gh/PhpGt/Fetch\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.status.php.gt/fetch-quality.svg\" alt=\"Code quality\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://app.codecov.io/gh/PhpGt/Fetch\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.status.php.gt/fetch-coverage.svg\" alt=\"Code coverage\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/PhpGt/Fetch\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.status.php.gt/fetch-version.svg\" alt=\"Current version\" /\u003e\n\u003c/a\u003e\n\u003ca href=\"https://www.php.gt/fetch\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://badge.status.php.gt/fetch-docs.svg\" alt=\"PHP.Gt/Fetch documentation\" /\u003e\n\u003c/a\u003e\n\n## Example usage: compute multiple HTTP requests in parallel, using `fetch`\n\n```php\n\u003c?php\n$http = new Gt\\Fetch\\Http();\n\n// Rather than creating the request now, `fetch` returns a Promise, \n// for later resolution with the BodyResponse.\n$http-\u003efetch(\"http://example.com/api/something.json\")\n-\u003ethen(function(BodyResponse $response) {\n// The first Promise resolves as soon as a response is received, even before\n// the body's content has completed downloading.\n\tif(!$response-\u003eok) {\n\t\techo \"Looks like there was a problem. Status code: \"\n\t\t\t. $response-\u003egetStatusCode() . PHP_EOL;\n\t\treturn null;\n\t}\n\n// Within this Promise callback, you have access to the body stream, but\n// to access the contents of the whole body, return a new Promise here:\n    return $response-\u003ejson();\n})\n-\u003ethen(function(Json $json) {\n// The second Promise resolves once the whole body has completed downloading.\n    echo \"Got JSON result length \"\n    \t. count($json-\u003eresults)\n    \t. PHP_EOL;\n\n// Notice that type-safe getters are available on all Json objects:\n    echo \"Name of first result: \"\n    \t. $json-\u003eresults[0]-\u003egetString(\"name\")\n    \t. PHP_EOL;\n});\n\n// A third request is made here to show a different type of body response:\n$http-\u003efetch(\"http://example.com/something.jpg\")\n-\u003ethen(function(BodyResponse $response) {\n    return $response-\u003eblob();\n})\n-\u003ethen(function($blob) {\n    echo \"Got JPG blob. Saving file.\" . PHP_EOL;\n    file_put_contents(\"/tmp/something.jpg\", $blob);\n});\n\n// Once all Promises are registered, all HTTP requests can be initiated in\n// parallel, with the callback function triggered when they are all complete. \n$http-\u003eall()-\u003ethen(function() {\n    echo \"All HTTP calls have completed!\" . PHP_EOL;\n});\n```\n\nFor more extensive examples, check out the code in the [example directory](/example).\n\n[fetch-standard]: https://fetch.spec.whatwg.org/\n[fetch-js]: https://developer.mozilla.org/en/docs/Web/API/Fetch_API\n","funding_links":["https://github.com/sponsors/phpgt"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Ffetch","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fphpgt%2Ffetch","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fphpgt%2Ffetch/lists"}