{"id":14984039,"url":"https://github.com/ivan770/laravel-httpclient","last_synced_at":"2025-04-10T19:43:15.730Z","repository":{"id":56994739,"uuid":"190936089","full_name":"ivan770/laravel-httpclient","owner":"ivan770","description":"HTTP client for Laravel, powered by Symfony components","archived":false,"fork":false,"pushed_at":"2020-12-08T12:13:35.000Z","size":56,"stargazers_count":8,"open_issues_count":0,"forks_count":2,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-10T08:17:00.440Z","etag":null,"topics":["help-wanted","http-client","https-client","laravel","php","symfony-component"],"latest_commit_sha":null,"homepage":null,"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/ivan770.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":"2019-06-08T21:19:40.000Z","updated_at":"2021-08-23T08:33:52.000Z","dependencies_parsed_at":"2022-08-21T10:40:44.180Z","dependency_job_id":null,"html_url":"https://github.com/ivan770/laravel-httpclient","commit_stats":null,"previous_names":[],"tags_count":15,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan770%2Flaravel-httpclient","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan770%2Flaravel-httpclient/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan770%2Flaravel-httpclient/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ivan770%2Flaravel-httpclient/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ivan770","download_url":"https://codeload.github.com/ivan770/laravel-httpclient/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248281424,"owners_count":21077423,"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":["help-wanted","http-client","https-client","laravel","php","symfony-component"],"created_at":"2024-09-24T14:08:21.592Z","updated_at":"2025-04-10T19:43:15.710Z","avatar_url":"https://github.com/ivan770.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Laravel HTTP client\n## Installation\n`composer require ivan770/laravel-httpclient`\n## Usage\n```php\n// Obtaining instance via Facade alias\nuse HttpClient;\n// You can use Facade class to access HttpClient\nuse Ivan770\\HttpClient\\Facades\\HttpClient;\n// Or, you can obtain HttpClient instance directly\nuse Ivan770\\HttpClient\\HttpClient;\npublic function method(HttpClient $client)\n```\n### Sending requests\nYou can also use [Symfony HttpClient documentation](https://symfony.com/doc/current/components/http_client.html)\n```php\n$response = $client-\u003eget(\"https://example.com\");\n$response = $client-\u003eget(\"https://example.com\", [\"query\" =\u003e [\"key\" =\u003e \"value\"]]);\n$response-\u003egetContent(); // Get response body, or collection, if response is JSON\n$response-\u003etoCollection(); // Transform JSON response to collection\n$response-\u003egetStatusCode(); // Get response status code\n$response-\u003egetHeaders(); // Get response headers\n\n// You can use HTTP request methods as client methods\n$client-\u003ehead(\"https://example.com\");\n$client-\u003epost(\"https://example.com\", [\"body\" =\u003e [\"key\" =\u003e \"value\"]]);\n$client-\u003epost(\"https://example.com\", [\"json\" =\u003e [\"key\" =\u003e \"value\"]]);\n$client-\u003eput(\"https://example.com\");\n$client-\u003edelete(\"https://example.com\");\n```\n### Using Request class\nHttpClient provides ability to create \"request classes\".\n\n`php artisan make:http HttpBinGet`\n\n```php\n\u003c?php\n\nuse Ivan770\\HttpClient\\HttpClient;\nuse Ivan770\\HttpClient\\Request\\Request;\nuse Ivan770\\HttpClient\\Response\\MockResponse;\n\nclass HttpBinGet extends Request\n{\n    // Request URL\n    protected $resource = \"https://httpbin.org/get\";\n\n    // Request method\n    protected $method = \"GET\";\n\n    // This method is called on request init.\n    // Here, you are able to use builder to modify your request\n    protected function defaultAttach(HttpClient $client)\n    {\n\t$client-\u003eauthBearer(\"test\");\n    }\n\n    protected function tests()\n    {\n        return [\n            \"success\" =\u003e MockResponse::make(\"Hello World!\"),\n        ];\n    }\n}\n\n// Execute request\napp(HttpBinGet::class)-\u003eexecute();\n\n// Execute request and receive result\napp(HttpBinGet::class)-\u003eget();\n\n// Modify request using \"attach\" method.\napp(HttpBinGet::class)-\u003eattach(function (HttpClient $client) {\n    $client-\u003eheaders([\"test\" =\u003e true]);\n})-\u003eexecute();\n\n// Request also forwards calls to HttpClient\napp(HttpBinGet::class)-\u003eheaders([\"test\" =\u003e true])-\u003eexecute();\n\n// Mock responses\n$response = app(HttpBinGet::class)-\u003emock(\"success\");\n\n$response-\u003egetContent(); // \"Hello World!\"\n$response-\u003egetStatus(); // 200\n$response-\u003egetHeaders(); // []\n```\n### BrowserKit usage\n```php\n\u003c?php\n\nuse Ivan770\\HttpClient\\Request\\Request;\nuse Ivan770\\HttpClient\\Contracts\\PassToBrowserKit;\n\n// Just implement PassToBrowserKit contract to start using BrowserKit\nclass HttpBinGet extends Request implements PassToBrowserKit\n{\n    // Request URL\n    protected $resource = \"https://httpbin.org/get\";\n\n    // Request method\n    protected $method = \"GET\";\n}\n```\n### Request builder\nYou can send your request parameters directly to client methods, but you can also use fluent request builder.\n```php\n// Add data to request\n$client-\u003equery([\"key\" =\u003e \"value\"])-\u003eget(\"https://example.com\")\n$client-\u003ebody([\"key\" =\u003e \"value\"])-\u003epost(\"https://example.com\")\n$client-\u003ejson([\"key\" =\u003e \"value\"])-\u003epost(\"https://example.com\")\n\n// Add custom headers to request\n$client-\u003eheaders([\"key\" =\u003e \"value\"])-\u003eget(\"https://example.com\");\n\n// Ignore redirects\n$client-\u003ewithoutRedirects()-\u003eget(\"https://example.com\");\n\n// Proxy\n$client-\u003eproxy(\"https://hostname:8080\")-\u003eget(\"https://example.com\");\n\n// Authentication\n$client-\u003eauth(\"auth_basic\", [\"username\", \"password\"])-\u003eget(\"https://example.com\");\n$client-\u003eauthBasic([\"username\", \"password\"])-\u003eget(\"https://example.com\");\n$client-\u003eauthBearer(\"tokenhere\")-\u003eget(\"https://example.com\");\n```\n\n### Arrayable parsing\nYou can use any Arrayable class (Eloquent models, collections, etc.) as data source for request\n```php\n$model = User::find(1);\n$client-\u003eparse($model)-\u003epost(\"https://example.com\");\n```\n\n### Data pipelining\nIf `illuminate/pipeline` is installed, you can send your data through pipelines.\nIf not, you can still pass your data to [Closure](https://www.php.net/manual/en/class.closure.php)\n```php\n$response = $client-\u003eget(\"https://example.com\");\n\n// Pass data to Closure\n$response-\u003ethen(function ($data) {\n    return $data;\n});\n\n// Use Laravel pipelines\n$pipes = [\n    ExamplePipe::class\n];\n$response-\u003epipeline()-\u003ethrough($pipes)-\u003ethen(function ($data) {\n    return $data;\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivan770%2Flaravel-httpclient","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fivan770%2Flaravel-httpclient","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fivan770%2Flaravel-httpclient/lists"}