{"id":28092622,"url":"https://github.com/auraphp/aura.http","last_synced_at":"2025-07-21T23:36:11.521Z","repository":{"id":62489567,"uuid":"1506891","full_name":"auraphp/Aura.Http","owner":"auraphp","description":"HTTP Request and Response tools","archived":false,"fork":false,"pushed_at":"2017-02-24T20:47:42.000Z","size":591,"stargazers_count":71,"open_issues_count":0,"forks_count":21,"subscribers_count":12,"default_branch":"1.x","last_synced_at":"2025-07-20T16:28:07.887Z","etag":null,"topics":["aura","php","request","response"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/auraphp.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":"2011-03-21T14:22:29.000Z","updated_at":"2024-12-16T06:48:27.000Z","dependencies_parsed_at":"2022-11-02T11:15:40.563Z","dependency_job_id":null,"html_url":"https://github.com/auraphp/Aura.Http","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/auraphp/Aura.Http","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auraphp%2FAura.Http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auraphp%2FAura.Http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auraphp%2FAura.Http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auraphp%2FAura.Http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/auraphp","download_url":"https://codeload.github.com/auraphp/Aura.Http/tar.gz/refs/heads/1.x","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/auraphp%2FAura.Http/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":266403308,"owners_count":23923406,"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","status":"online","status_checked_at":"2025-07-21T11:47:31.412Z","response_time":64,"last_error":null,"robots_txt_status":null,"robots_txt_updated_at":null,"robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["aura","php","request","response"],"created_at":"2025-05-13T13:23:51.079Z","updated_at":"2025-07-21T23:36:11.492Z","avatar_url":"https://github.com/auraphp.png","language":"PHP","readme":"Aura HTTP\n=========\n\n[![Build Status](https://travis-ci.org/auraphp/Aura.Http.png?branch=develop)](https://travis-ci.org/auraphp/Aura.Http)\n\nThe Aura HTTP package provides objects to build and send HTTP requests and\nresponses, including `multipart/form-data` requests, with streaming of file\nresources when using the `curl` adapter.\n\nThis package is compliant with [PSR-0][], [PSR-1][], and [PSR-2][]. If you\nnotice compliance oversights, please send a patch via pull request.\n\n[PSR-0]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-0.md\n[PSR-1]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-1-basic-coding-standard.md\n[PSR-2]: https://github.com/php-fig/fig-standards/blob/master/accepted/PSR-2-coding-style-guide.md\n\nGetting Started\n===============\n\nInstantiation\n-------------\n\nThe easiest way to get started is to use the `scripts/instance.php` script to\ninstantiate an HTTP `Manager` object.\n\n```php\n\u003c?php\n$http = include '/path/to/Aura.Http/scripts/instance.php';\n```\n\nYou can then create new `Request` and `Response` objects, and send them via\nthe `Manager`.\n\n```php\n\u003c?php\n// send a response\n$response = $http-\u003enewResponse();\n$response-\u003eheaders-\u003eset('Content-Type', 'text/plain');\n$response-\u003esetContent('Hello World!');\n$http-\u003esend($response);\n\n// make a request and get a response stack\n$request = $http-\u003enewRequest();\n$request-\u003esetUrl('http://example.com');\n$stack = $http-\u003esend($request);\necho $stack[0]-\u003econtent;\n```\n\nHTTP Responses\n==============\n\nInstantiation\n-------------\n\nUse the `Manager` to create a new HTTP response.\n\n```php\n\u003c?php\n$response = $http-\u003enewResponse();\n```\n\nSetting And Getting Content\n---------------------------\n\nTo set the content of the `Response`, use `setContent()`.\n\n```php\n\u003c?php\n$html = '\u003chtml\u003e'\n      . '\u003chead\u003e\u003ctitle\u003eTest\u003c/title\u003e\u003c/head\u003e'\n      . '\u003cbody\u003eHello World!\u003c/body\u003e'\n      . '\u003c/html\u003e';\n$response-\u003esetContent($html);\n```\n\nInstead of a string, the content may be a file resource; when the response is\nsent, the file will be streamed out via `fread()`.\n\nTo get the content, use `getContent()` or access the `$content` property.\n\n\nSetting And Getting Headers\n---------------------------\n\nTo set headers, access the `$headers` property, and use its `set()` method.\n\n```php\n\u003c?php\n$response-\u003eheaders-\u003eset('Header-Label', 'header value');\n```\n\nYou can also set all the headers at once by passing an array of key-value\npairs where the key is the header label and the value is one or more header\nvalues.\n\n```php\n\u003c?php\n$response-\u003eheaders-\u003esetAll([\n    'Header-One' =\u003e 'header one value',\n    'Header-Two' =\u003e [\n        'header two value A',\n        'header two value B',\n        'header two value C',\n    ],\n]);\n```\n\n\u003e N.b.: Header labels are sanitized and normalized, so if you enter a label\n\u003e `header_foo` it will be converted to `Header-Foo`.\n\nTo get the headers, use `getHeaders()` or access the `$headers` property and\nuse the `get()` method.\n\n```php\n\u003c?php\n// set a header\n$response-\u003eheaders-\u003eset('Content-Type', 'text/plain');\n\n// get a header\n$header = $response-\u003eheaders-\u003eget('Content-Type');\n\n// $header-\u003elabel is 'Content-Type'\n// $header-\u003evalue is 'text/plain'\n```\n\nSetting and Getting Cookies\n---------------------------\n\nTo set cookies, access the `$cookies` property . Pass the cookie name and an\narray of information about the cookie (including its value).\n\n```php\n\u003c?php\n$response-\u003ecookies-\u003eset('cookie_name', [\n    'value'    =\u003e 'cookie value', // cookie value\n    'expire'   =\u003e time() + 3600,  // expiration time in unix epoch seconds\n    'path'     =\u003e '/path',        // server path for the cookie\n    'domain'   =\u003e 'example.com',  // domain for the cookie\n    'secure'   =\u003e false,          // send by ssl only?\n    'httponly' =\u003e true,           // send by http/https only?\n]);\n```\n\nThe information array keys mimic the [setcookies()](http://php.net/setcookies)\nparameter names. You only need to provide the parts of the array that you\nneed; the remainder will be filled in with `null` defaults for you.\n\nYou can also set all the cookies at once by passing an array of key-value\npairs, where the key is the cookie name and the value is a cookie information\narray.\n\n```php\n\u003c?php\n$response-\u003ecookies-\u003esetAll([\n    'cookie_foo' =\u003e [\n        'value' =\u003e 'value for cookie foo',\n    ],\n    'cookie_bar' =\u003e [\n        'value' =\u003e 'value for cookie bar',\n    ],\n]);\n```\n\nTo get cookies, use `getCookies()` or access the `$cookies` property and use\nthe `get()` method.\n\n```php\n\u003c?php\n$cookie = $response-\u003ecookies-\u003eget('cookie_foo');\n```\n\n\nSetting and Getting the Status\n------------------------------\n\nTo set the HTTP response status, use `setStatusCode()` and `setStatusText()`.\nThe `setStatusCode()` method automatically sets the text for known codes.\n\n```php\n\u003c?php\n// automatically sets the status text to 'Not Modified'\n$response-\u003esetStatusCode(304);\n\n// change the status text to something else\n$response-\u003esetStatusText('Same As It Ever Was');\n```\n\n\u003e N.b.: By default, a new `Response` starts with a status of `'200 OK'`.\n\nTo get the response status, use `getStatusCode()` and `getStatusText()`.\n\n\nSending the Response\n--------------------\n\nOnce you have set the content, headers, cookies, and status, you can send the\nresponse using the HTTP `Manager` object.\n\n```php\n\u003c?php\n$http-\u003esend($response);\n```\n\nThis will send all the headers using [header()](http://php.net/header) and all\nthe cookies using [setcookie()](http://php.net/setcookie).\n\nIf the content is a string, it will be `echo`-ed; if the content is a file\nresource, it will be streamed out with `fread()`.\n\n\u003e N.b.: You can only send the `Response` once. If you try to send it again,\n\u003e or if you try to send another response of any sort with headers on it, you\n\u003e will get a `HeadersSent` exception.\n\n\nHTTP Requests\n=============\n\nInstantiation\n-------------\n\nUse the `Manager` to create a new HTTP request.\n\n```php\n\u003c?php\n$request = $http-\u003enewRequest();\n```\n\nSetting and Getting Headers and Cookies\n---------------------------------------\n\nYou can set and get headers and cookies just as with a `Response` object,\ndescribed above.\n\n\nSetting and Getting Content\n---------------------------\n\nYou can set and get content just as with a `Response` object, described above.\n\n\u003e N.b.: Content will be sent only if the request method is `POST` or `PUT`.\n\nIf the `Request` content is a string, it will be sent as-is.\n\nIf the `Request` content is a file resource, it will be read from disk and\nsent.\n\nIf the content is an array, it will be converted to `x-www-form-urlencoded` or\n`multipart/form-data`. The array may specify files to be uploaded by prefixing\nthe array value with `@`.\n\n\u003e **WARNING:** Be sure to sanitize user data to make sure only values intended\n\u003e as file uploads begin with `@`.\n\n```php\n\u003c?php\n// set content directly as a string\n$request-\u003esetContent(json_encode([\n    'foo' =\u003e 'bar',\n    'baz' =\u003e 'dib',\n]));\n\n// set content to a file to be be streamed out\n$fh = fopen('/path/to/file');\n$request-\u003esetContent($fh);\n\n// set content to an array of data, which will be converted\n// to x-www-form-urlencoded or multipart/form-data.\n$request-\u003esetContent([\n    'foo' =\u003e 'bar',\n    'baz' =\u003e 'dib',\n]);\n\n// set content to an array of data with files to be uploaded\n// (note the use of '@' to indicate a file).\n$request-\u003esetContent([\n    'foo' =\u003e 'bar',\n    'baz' =\u003e 'dib',\n    'zim' =\u003e '@/path/to/file'\n]);\n```\n\n\nSetting URL and Method\n----------------------\n\nTo set the URL and method, do the following:\n\n```php\n\u003c?php\nuse Aura\\Http\\Message\\Request;\n$request-\u003esetUrl('http://example.com');\n$request-\u003esetMethod(Request::METHOD_POST);\n```\n\n(By default, all requests use a `Aura\\Http\\Message\\Request::METHOD_GET` method to begin with.)\n\n\nSetting Authentication\n----------------------\n\nTo set authentication credentials, pick the authentication type, then set\na username and password.\n\n```php\n\u003c?php\nuse Aura\\Http\\Message\\Request;\n$request-\u003esetAuth(Request::AUTH_BASIC);\n$request-\u003esetUsername('username');\n$request-\u003esetPassword('password');\n```\n\nAvailable authentication types are `Aura\\Http\\Message\\Request::AUTH_BASIC` and\n`Aura\\Http\\Message\\Request::AUTH_DIGEST`.\n\n\nSending the Request\n-------------------\n\nYou can send the request via the `Manager` object; it returns a `ResponseStack`.\n\n```php\n\u003c?php\n$stack = $http-\u003esend($request);\n// $stack[0]-\u003eheaders contains the headers of the last response\n// $stack[0]-\u003econtent contains the content of the last response\n```\n\nThe `$stack` is an `Aura\\Http\\Message\\Response\\Stack` containing all the\nresponses, including redirects. The stack order is last in first out. Each\nitem in the stack is an `Aura\\Http\\Message\\Response` object.\n\n\nFurther Examples\n----------------\n\nMaking a GET request to the Github API to list Aura's repositories:\n\n```php\n\u003c?php\n$request-\u003esetUrl('https://api.github.com/orgs/auraphp/repos');\n$request-\u003egetHeaders()-\u003eadd('User-Agent', 'Aura Bot v1');\n$stack = $http-\u003esend($request);\n$repos = json_decode($stack[0]-\u003econtent);\nforeach ($repos as $repo) {\n    echo $repo-\u003ename . PHP_EOL;\n}\n```\n\nMaking a custom POST request:\n\n```php\n\u003c?php\nuse Aura\\Http\\Message\\Request;\n$request-\u003esetUrl('http://example.com/submit.php');\n$request-\u003esetMethod(Request::METHOD_POST);\n$request-\u003esetContent(json_encode(['hello' =\u003e 'world']));\n$request-\u003eheaders-\u003eset('Content-Type', 'application/json');\n$stack = $http-\u003esend($request);\n```\n\nSaving the response content to a file:\n\n```php\n\u003c?php\n$fp = fopen('/path/to/download.ext', 'wb+');\n$request-\u003esetUrl('http://example.com/download.ext');\n$request-\u003esetSaveToStream($fp);\n$stack = $http-\u003esend($request);\n// $stack[0]-\u003econtent will be a file stream\n```\n\n\nHTTP Transport and Adapters\n===========================\n\nThe HTTP `Manager` uses a `Transport` object to send requests.  You can\nspecify various options for the transport.\n\n```php\n// use a cookie jar for all requests\n$http-\u003etransport-\u003eoptions-\u003esetCookieJar('/path/to/cookie.jar');\n\n// the maximum number of request redirects\n$http-\u003etransport-\u003eoptions-\u003esetMaxRedirects(10);\n\n// the request timeout in seconds\n$http-\u003etransport-\u003eoptions-\u003esetTimeout(10);\n\n// the proxy host, port, username, and password\n$http-\u003etransport-\u003eoptions-\u003esetProxy('proxy.example.com');\n$http-\u003etransport-\u003eoptions-\u003esetProxyPort('12345');\n$http-\u003etransport-\u003eoptions-\u003esetProxyUsername('username');\n$http-\u003etransport-\u003eoptions-\u003esetProxyPassword('password');\n\n// ssl options\n$http-\u003etransport-\u003eoptions-\u003esetSslCafile('/path/to/cafile');\n$http-\u003etransport-\u003eoptions-\u003esetSslCapath('capath');\n$http-\u003etransport-\u003eoptions-\u003esetSslLocalCert('/path/to/local.crt');\n$http-\u003etransport-\u003eoptions-\u003esetSslPassphrase('passphrase');\n$http-\u003etransport-\u003eoptions-\u003esetSslVerifyPeer(true);\n```\n\nThe transport uses an `Adapter` to handle the actual sending of requests.\nThere are two adapters available:\n\n- `Aura\\Http\\Request\\Adapter\\Curl`, which is used automatically when the\n  `curl` extension is loaded.  This adapter will stream file resources\n  directly to and from disk, without loading the entire file into memory.\n\n- `Aura\\Http\\Request\\Adapter\\Stream`, which is the fallback if `curl` is not\n  loaded. This adapter is not suitable for sending or receiving large files.\n  Each file will loaded into memory. This is a limitation in PHP HTTP streams.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauraphp%2Faura.http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fauraphp%2Faura.http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fauraphp%2Faura.http/lists"}