{"id":17723232,"url":"https://github.com/aaronpk/p3k-http","last_synced_at":"2026-02-25T23:32:46.374Z","repository":{"id":57034837,"uuid":"76749409","full_name":"aaronpk/p3k-http","owner":"aaronpk","description":"A simple HTTP client, used by https://p3k.io projects","archived":false,"fork":false,"pushed_at":"2024-10-20T19:47:18.000Z","size":25,"stargazers_count":13,"open_issues_count":1,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-04-15T03:53:46.948Z","etag":null,"topics":["http","p3k"],"latest_commit_sha":null,"homepage":"","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/aaronpk.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","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}},"created_at":"2016-12-17T22:15:06.000Z","updated_at":"2024-10-20T19:47:17.000Z","dependencies_parsed_at":"2024-10-25T20:00:06.410Z","dependency_job_id":null,"html_url":"https://github.com/aaronpk/p3k-http","commit_stats":{"total_commits":15,"total_committers":2,"mean_commits":7.5,"dds":0.06666666666666665,"last_synced_commit":"cf9c5b7cdbe1800bfb9587a20953ed8d20322e0b"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpk%2Fp3k-http","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpk%2Fp3k-http/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpk%2Fp3k-http/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/aaronpk%2Fp3k-http/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/aaronpk","download_url":"https://codeload.github.com/aaronpk/p3k-http/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249003955,"owners_count":21196794,"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","p3k"],"created_at":"2024-10-25T15:42:17.106Z","updated_at":"2026-02-25T23:32:41.345Z","avatar_url":"https://github.com/aaronpk.png","language":"PHP","readme":"# p3k-http\n\nA simple HTTP client, used by https://p3k.io projects.\n\n## Usage\n\n### GET\n\n```php\n$http = new p3k\\HTTP();\n$headers = [\n  'Accept: text/html, */*'\n];\n$response = $http-\u003eget('http://example.com/', $headers);\n```\n\n### POST\n\n```php\n$http = new p3k\\HTTP();\n$headers = [\n  'Accept: application/json',\n  'Content-type: application/json'\n];\n$response = $http-\u003epost('http://example.com/', json_encode([\n  'foo' =\u003e 'bar'\n], $headers);\n```\n\n### HEAD\n\n```php\n$http = new p3k\\HTTP();\n$headers = [\n  'Accept: text/html, */*'\n];\n$response = $http-\u003ehead('http://example.com/', $headers);\n```\n\n### Response\n\nThe get/post/head functions will return an array with the following properties:\n\n* `code` - integer, the HTTP response code that was returned\n* `headers` - array, the HTTP headers returned\n* `rels` - array, the parsed HTTP rel values from any `Link` headers\n* `body` - string, the body of the HTTP response, or false/omit for a HEAD request\n* `error` - string, an error string. see below for the enumerated list.\n* `error_description` - string,\n* `url` - string, the final URL retrieved after following any redirects\n* `debug` - string, the full HTTP response\n\n#### `headers`\n\nThe `headers` key will be an array of all the header values returned. The values will be either a string or array depending on whether there were multiple values returned for a given header name.\n\n```\n    [headers] =\u003e Array\n        (\n            [Server] =\u003e nginx/1.12.0\n            [Content-Type] =\u003e text/html; charset=UTF-8\n            [Transfer-Encoding] =\u003e chunked\n            [Connection] =\u003e keep-alive\n            [Cache-Control] =\u003e no-cache\n            [Link] =\u003e Array\n                (\n                    [0] =\u003e \u003chttps://switchboard.p3k.io/\u003e; rel=\"hub\"\n                    [1] =\u003e \u003chttps://aaronparecki.com/auth\u003e; rel=\"authorization_endpoint\"\n                    [2] =\u003e \u003chttps://aaronparecki.com/micropub\u003e; rel=\"micropub\"\n                    [3] =\u003e \u003chttps://aaronparecki.com/auth/token\u003e; rel=\"token_endpoint\"\n                    [4] =\u003e \u003chttps://aaronparecki.com/\u003e; rel=\"self\"\n                )\n\n            [Date] =\u003e Fri, 28 Apr 2017 18:40:42 GMT\n            [Strict-Transport-Security] =\u003e max-age=2592000\n            [X-No-Cache] =\u003e 0\n            [X-Cache] =\u003e EXPIRED\n        )\n```\n\n#### `rels`\n\nThe `rels` key will be the parsed version of any HTTP `Link` headers that contain a rel value. All values will be arrays even if there is only one value.\n\n```\n    [rels] =\u003e Array\n        (\n            [hub] =\u003e Array\n                (\n                    [0] =\u003e https://switchboard.p3k.io/\n                )\n\n            [authorization_endpoint] =\u003e Array\n                (\n                    [0] =\u003e https://aaronparecki.com/auth\n                )\n\n            [micropub] =\u003e Array\n                (\n                    [0] =\u003e https://aaronparecki.com/micropub\n                )\n\n            [token_endpoint] =\u003e Array\n                (\n                    [0] =\u003e https://aaronparecki.com/auth/token\n                )\n\n            [self] =\u003e Array\n                (\n                    [0] =\u003e https://aaronparecki.com/\n                )\n        )\n```\n\n\n### Options\n\nThere are a few options you can set when making HTTP requests, to configure how the request will behave.\n\n* `$http-\u003eset_user_agent('String')` - A shortcut for setting the user agent header.\n* `$http-\u003eset_max_redirects(2)` - The maximum number of redirects to follow. Defaults to 8.\n* `$http-\u003eset_timeout(10)` - The timeout in seconds for waiting for a response. Defaults to 4.\n\n#### User Agent\n\nYou can set the user agent when you first instantiate the HTTP object:\n\n```php\n$http = new p3k\\HTTP('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 p3k-http/0.1.0');\n$http-\u003eget('http://example.com/');\n```\n\nAlternately, you can change it before each request:\n\n```php\n$http = new p3k\\HTTP();\n$http-\u003eset_user_agent('Mozilla/5.0 (Macintosh; Intel Mac OS X 10_12_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.133 Safari/537.36 p3k-http/0.1.0');\n$http-\u003eget('http://example.com/');\n```\n\n\n## Transports\n\nBy default, the library will use the PHP curl functions to make the HTTP request.\n\nYou can optionally define your own transport to use to make HTTP requests instead. This allows you to use an existing HTTP request mechanism you may have rather than using curl or the PHP stream functions.\n\nDefine a new class that implements the `p3k\\HTTP\\Transport` interface. That interface documents the return values expected as well.\n\nThen you can set the transport after you create the main HTTP object.\n\n```php\n$http = new p3k\\HTTP();\n$http-\u003eset_transport(new p3k\\HTTP\\Stream());  // or your custom class here\n```\n\nThe library ships with two alternative transport mechanisms, `p3k\\HTTP\\Stream` and `p3k\\HTTP\\Test`. The Stream transport uses `file_get_contents` with all the necessary config options to make it work. This is useful when running in Google App Engine. The Test transport will read HTTP responses from files, so that you can write tests that simulate making HTTP calls. See https://github.com/aaronpk/XRay/tree/master/tests for an example of using this transport.\n\n\n## License\n\nCopyright 2017 by Aaron Parecki\n\nAvailable under the MIT license.\n\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpk%2Fp3k-http","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Faaronpk%2Fp3k-http","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Faaronpk%2Fp3k-http/lists"}