{"id":15393112,"url":"https://github.com/shgysk8zer0/http","last_synced_at":"2025-03-27T23:42:46.909Z","repository":{"id":79780734,"uuid":"270359922","full_name":"shgysk8zer0/http","owner":"shgysk8zer0","description":"PHP implementation of JavaScript's Request, Response, Headers, \u0026 URL classes","archived":false,"fork":false,"pushed_at":"2020-06-23T23:30:03.000Z","size":153,"stargazers_count":1,"open_issues_count":3,"forks_count":0,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-02-02T01:44:42.417Z","etag":null,"topics":["fetch-api","formdata","headers","php","php7","request","response","url","urlsearchparams"],"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/shgysk8zer0.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"shgysk8zer0","liberapay":"shgysk8zer0"}},"created_at":"2020-06-07T16:10:13.000Z","updated_at":"2020-06-23T23:29:02.000Z","dependencies_parsed_at":"2023-02-26T18:31:34.883Z","dependency_job_id":null,"html_url":"https://github.com/shgysk8zer0/http","commit_stats":{"total_commits":33,"total_committers":1,"mean_commits":33.0,"dds":0.0,"last_synced_commit":"c4d0ee6b2c76ff8ac43164149a2f0e8f3e65db5d"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":"shgysk8zer0/blank-repo","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/shgysk8zer0%2Fhttp/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/shgysk8zer0","download_url":"https://codeload.github.com/shgysk8zer0/http/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245944063,"owners_count":20697948,"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":["fetch-api","formdata","headers","php","php7","request","response","url","urlsearchparams"],"created_at":"2024-10-01T15:17:53.707Z","updated_at":"2025-03-27T23:42:46.890Z","avatar_url":"https://github.com/shgysk8zer0.png","language":"PHP","readme":"# http\n[![PHP Lint](https://github.com/shgysk8zer0/http/workflows/PHP%20Lint/badge.svg)](https://github.com/shgysk8zer0/http/actions?query=workflow%3A%22PHP+Lint%22)\n[![Super Linter](https://github.com/shgysk8zer0/http/workflows/Lint%20Code%20Base/badge.svg)](https://github.com/shgysk8zer0/http/actions?query=workflow%3A%22Lint+Code+Base%22)\n[![GitHub license](https://img.shields.io/github/license/shgysk8zer0/http.svg)](https://github.com/shgysk8zer0/http/blob/master/LICENSE)\n![GitHub last commit](https://img.shields.io/github/last-commit/shgysk8zer0/http.svg)\n![GitHub release](https://img.shields.io/github/release/shgysk8zer0/http.svg)\n\n[![Donate using Liberapay](https://img.shields.io/liberapay/receives/shgysk8zer0.svg?logo=liberapay)](https://liberapay.com/shgysk8zer0/donate \"Donate using Liberapay\")\n![Keybase PGP](https://img.shields.io/keybase/pgp/shgysk8zer0.svg)\n![Keybase BTC](https://img.shields.io/keybase/btc/shgysk8zer0.svg)\n\n![GitHub followers](https://img.shields.io/github/followers/shgysk8zer0.svg?style=social)\n![GitHub forks](https://img.shields.io/github/forks/shgysk8zer0/http.svg?style=social)\n![GitHub stars](https://img.shields.io/github/stars/shgysk8zer0/http.svg?style=social)\n![Twitter Follow](https://img.shields.io/twitter/follow/shgysk8zer0.svg?style=social)\n- - -\n\u003e A PHP implementation of JavaScript's [`Request`](https://developer.mozilla.org/en-US/docs/Web/API/Request),\n[`Response`](https://developer.mozilla.org/en-US/docs/Web/API/Response),\n[`URL`](https://developer.mozilla.org/en-US/docs/Web/API/URL/),\n[`URLSearchParams`](https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams),\n[`FormData`](https://developer.mozilla.org/en-US/docs/Web/API/FormData),\nand [`Headers`](https://developer.mozilla.org/en-US/docs/Web/API/Headers)\ninterfaces.\n\n## Example\n```php\n\u003c?php\n\nuse \\shgysk8zer0\\HTTP\\{Request, Response, Body, FormData, Headers, File, URL};\n\nuse \\shgysk8zer0\\HTTP\\Abstracts\\{HTTPStatusCodes as HTTP};\n\nuse \\shgysk8zer0\\PHPAPI\\{ConsoleLogger, FileCache};\n\nuse \\DateInterval;\n\nspl_autoload_regiser('spl_autoload');\n\nset_include_path($classes_dir . PATH_SEPARATOR . get_include_path());\n\n\ntry {\n  $url = new URL('../some/endpoint', 'https://example.com/wrong-path/');\n\n  $cache = new FileCache();\n  $logger = new ConsoleLogger();\n\n  $req = new Request($url, [\n    'method'      =\u003e 'POST',\n    'referrer'    =\u003e 'no-referrer',\n    'redirect'    =\u003e 'follow',\n    'credentials' =\u003e 'omit',\n    'cache'       =\u003e 'default',\n    'headers'     =\u003e new Headers([\n        'Accept' =\u003e 'application/json',\n        'X-FOO'  =\u003e 'bar',\n    ]),\n    'body'        =\u003e new FormData([\n        'username' =\u003e $username,\n        'token'    =\u003e $token,\n        'file'     =\u003e new File($filename, null, 'file'),\n        'upload'   =\u003e new UploadFile('upload'),\n    ])\n  ]);\n\n  $req-\u003esetLogger($logger);\n\n  // For compatibility with `CacheInterface` `Request.cache = 'default'` -\u003e `Request::setCacheMode('default')`\n  // and `Request::setCache(CacheInterface $cache)`\n  $req-\u003esetCache($cache);\n\n  if ($resp = $req-\u003esend($timeout)) {\n    $resp-\u003eheaders-\u003eset('Content-SecurityPolicy', ContentSecurityPolicy::fromIniFile('./csp.ini'));\n\n    $resp-\u003eheaders-\u003eset('Feature-Policy', new FeaturePolicy([\n      'geolocation' =\u003e 'self',\n      'camera'      =\u003e 'self',\n    ]));\n\n    $resp-\u003eheaders-\u003eappend('Set-Cookie', new Cookie('name','value', [\n      'secure'   =\u003e true,\n      'httpOnly' =\u003e true,\n      'expires'  =\u003e new DateInterval('P1D'),\n      'sameSite' =\u003e 'Strict',\n    ]);\n\n    // `Response::send()` sends HTTP status code, headers, \u0026 body\n    $resp-\u003esend();\n  } else {\n    $resp = new Response(new Body('An unknown error occured'), [\n      'headers' =\u003e new Headers([\n        'Content-Security-Policy' =\u003e new ContentSecurityPolicy(['default-src' =\u003e 'self']),\n        'Content-Type'            =\u003e 'text/plain',\n      ]),\n      'status'                    =\u003e HTTP::BAD_GATEWAY,\n    ]);\n\n    $resp-\u003esend();\n  }\n} catch (Throwable $e) {\n  $logger-\u003eerror('[{class} {code}] \"{message}\" at {file}:{line}', [\n    'class'   =\u003e get_class($e),\n    'code'    =\u003e $e-\u003egetCode(),\n    'message' =\u003e $e-\u003egetMessage(),\n    'file'    =\u003e $e-\u003egetFile(),\n    'line'    =\u003e $e-\u003egetLine(),\n  ]);\n\n  $resp = new Response(new Body('An error occured'), [\n    'status'  =\u003e HTTP::INTERNAL_SERVER_ERROR,\n    'headers' =\u003e new Headers([\n      'Content-Type' =\u003e 'text/plain',\n    ]),\n  ]);\n\n  $resp-\u003esend();\n}\n```\n\n## Installation\nThis is built to be installed as a submodule and loaded using [`spl_autoload`](https://www.php.net/manual/en/function.spl-autoload)\n\nTo install, just\n```bash\ngit submodule add https://github.com/shgysk8zer0/http.git $classes_dir/shgysk8zer0/http\n```\n\n## Dependencies\nLoggers and caches are used from [shgysk8zer0/PHPAPI](https://github.com/shgysk8zer0/phpapi).\nYou will need to add that as a submodule to `$classes_dir/shgysk8zer0/phpapi`.\n","funding_links":["https://github.com/sponsors/shgysk8zer0","https://liberapay.com/shgysk8zer0","https://liberapay.com/shgysk8zer0/donate"],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshgysk8zer0%2Fhttp","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fshgysk8zer0%2Fhttp","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fshgysk8zer0%2Fhttp/lists"}