{"id":20027748,"url":"https://github.com/vinelab/http","last_synced_at":"2025-04-09T16:20:30.748Z","repository":{"id":8716242,"uuid":"10385908","full_name":"Vinelab/http","owner":"Vinelab","description":"A smart, simple and fault-tolerant HTTP client for sending and receiving JSON and XML","archived":false,"fork":false,"pushed_at":"2019-09-25T08:25:17.000Z","size":59,"stargazers_count":56,"open_issues_count":6,"forks_count":30,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-05-05T10:02:52.743Z","etag":null,"topics":["fault-tolerance","http","http-client","laravel","php"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Vinelab.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2013-05-30T15:32:34.000Z","updated_at":"2024-02-15T05:46:03.000Z","dependencies_parsed_at":"2022-09-19T06:20:41.677Z","dependency_job_id":null,"html_url":"https://github.com/Vinelab/http","commit_stats":null,"previous_names":[],"tags_count":23,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vinelab%2Fhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vinelab%2Fhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vinelab%2Fhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Vinelab%2Fhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Vinelab","download_url":"https://codeload.github.com/Vinelab/http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248065281,"owners_count":21041872,"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":["fault-tolerance","http","http-client","laravel","php"],"created_at":"2024-11-13T09:11:36.301Z","updated_at":"2025-04-09T16:20:30.725Z","avatar_url":"https://github.com/Vinelab.png","language":"PHP","readme":"![build status](https://travis-ci.org/Vinelab/http.png?branch=master \"build status\")\n\n[![Dependency Status](https://www.versioneye.com/user/projects/53efc9a613bb06cc6f0004b0/badge.svg?style=flat)](https://www.versioneye.com/user/projects/53efc9a613bb06cc6f0004b0)\n\n[![SensioLabsInsight](https://insight.sensiolabs.com/projects/0663136a-6dde-4159-bc96-d1749599dca4/big.png)](https://insight.sensiolabs.com/projects/0663136a-6dde-4159-bc96-d1749599dca4)\n\n# http://Client\n\nA smart, simple and fault-tolerant HTTP client for sending and recieving JSON and XML.\n\n\n## Installation\n\n### Composer\n\n`composer require vinelab/http`\n\n```php\n// change this to point correctly according\n// to your folder structure.\nrequire './vendor/autoload.php';\n\nuse Vinelab\\Http\\Client as HttpClient;\n\n$client = new HttpClient;\n\n$response = $client-\u003eget('echo.jsontest.com/key/value/something/here');\n\nvar_dump($response-\u003ejson());\n```\n\n### Laravel\n\nEdit **app.php** and add ```'Vinelab\\Http\\HttpServiceProvider',``` to the ```'providers'``` array.\n\nIt will automatically alias itself as **HttpClient** so no need to alias it in your **app.php**, unless you would like to customize it - in that case edit your **'aliases'** in **app.php** adding ``` 'MyHttp'\t  =\u003e 'Vinelab\\Http\\Facades\\Client',```\n\n## Usage\n\n### GET\n\n#### Simple\n\n```php\n$response = HttpClient::get('http://example.org');\n\n// raw content\n$response-\u003econtent();\n```\n\n#### With Params\n\n```php\n$request = [\n\t'url' =\u003e 'http://somehost.net/something',\n\t'params' =\u003e [\n\n\t\t'id'     =\u003e '12350ME1D',\n\t\t'lang'   =\u003e 'en-us',\n\t\t'format' =\u003e 'rss_200'\n\t]\n];\n\n$response = HttpClient::get($request);\n\n// raw content\n$response-\u003econtent();\n\n// in case of json\n$response-\u003ejson();\n\n// XML\n$response-\u003exml();\n```\n\n### POST\n\n```php\n$request = [\n\t'url' =\u003e 'http://somehost.net/somewhere',\n\t'params' =\u003e [\n\n\t\t'id'     =\u003e '12350ME1D',\n\t\t'lang'   =\u003e 'en-us',\n\t\t'format' =\u003e 'rss_200'\n\t]\n];\n\n$response = HttpClient::post($request);\n\n// raw content\n$response-\u003econtent();\n\n// in case of json\n$response-\u003ejson();\n\n// XML\n$response-\u003exml();\n```\n\n### Options\nThese options work with all requests.\n\n#### Timeout\n\nYou can set the `timeout` option in order to specify the number of seconds that your request will fail, if not completed.\n\n```php\n$request = [\n\t'url' =\u003e 'http://somehost.net/somewhere',\n\t'params' =\u003e [\n\n\t\t'id'     =\u003e '12350ME1D',\n\t\t'lang'   =\u003e 'en-us',\n\t\t'format' =\u003e 'rss_200'\n\t],\n\t'timeout' =\u003e 10\n];\n```\n\n### Headers\n\n```php\n$response = HttpClient::get([\n\t'url' =\u003e 'http://somehost.net/somewhere',\n\t'headers' =\u003e ['Connection: close', 'Authorization: some-secret-here']\n]);\n\n// The full headers payload\n$response-\u003eheaders();\n```\n\n### Basic Auth\n\n```php\n$response = HttpClient::get([\n\t'url' =\u003e 'http://somehost.net/somewhere',\n\t'auth' =\u003e [\n\t\t'username' =\u003e 'user',\n\t\t'password' =\u003e 'pass'\n\t],\n\t'params' =\u003e [\n\t\t'var1'     =\u003e 'value1',\n\t\t'var2'   =\u003e 'value2'\n\t]\n]);\n```\n\n### Digest Auth\n\n```php\n$response = HttpClient::get([\n\t'url' =\u003e 'http://some.where.url',\n\t'digest' =\u003e [\n\t\t'username' =\u003e 'user',\n\t\t'password' =\u003e 'pass'\n\t],\n\t'params' =\u003e [\n\t\t'var1'     =\u003e 'value1',\n\t\t'var2'   =\u003e 'value2'\n\t]\n]);\n```\n\n### Enforce HTTP Version\n\n```php\nHttpClient::get(['version' =\u003e 1.1, 'url' =\u003e 'http://some.url']);\n```\n\n### Raw Content\n\n```php\nHttpClient::post(['url' =\u003e 'http://to.send.to', 'content' =\u003e 'Whatever content here may go!']);\n```\n\n#### Custom Query String\n\nThe content passed in the `content` key will be concatenated to the *URL* followed by a *?*\n\n```php\nHttpClient::get(['url' =\u003e 'http://my.url', 'content' =\u003e 'a=b\u0026c=d']);\n```\n\n\u003e It is pretty much the same process with different HTTP Verbs. Supports ``` GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD ```\n\n## Fault Tolerance\n\nFault tolerance allows the request to be re-issued when it fails (i.e. timeout).\nThis is useful in cases such as Microservices: When a service is down and is being called by another service,\nwith fault tolerance the request will be re-issued in the hopes of the destination service being up again.\n\nIssue a fault-tolerant request by setting the `tolerant` flag to `true` in the request. Also, specify\nthe time it should wait until it tries again with `timeUntilNextTry` (in seconds) and the number of tries\nbefore it is considered a failure with `triesUntilFailure` (in seconds).\n\n```php\n$request = [\n\t'url' =\u003e 'http://somehost.net/somewhere',\n\t'params' =\u003e [\n\n\t\t'id'     =\u003e '12350ME1D',\n\t\t'lang'   =\u003e 'en-us',\n\t\t'format' =\u003e 'rss_200'\n\t],\n\t'timeout' =\u003e 10\n\t'tolerant' =\u003e true,\n\t'timeUntilNextTry' =\u003e 1,\n\t'triesUntilFailure' =\u003e 3\n];\n```\n\nIn case of timeout occurance, a `HttpClientRequestFailedException` will be thrown.\n\n\u003e **IMPORTANT! Notice**: In order to make use of fault tolerance option, you must specify the `timeout` parameter too.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinelab%2Fhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvinelab%2Fhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvinelab%2Fhttp/lists"}