{"id":18656267,"url":"https://github.com/bayfrontmedia/php-http-response","last_synced_at":"2025-04-11T17:32:11.386Z","repository":{"id":39407676,"uuid":"286538986","full_name":"bayfrontmedia/php-http-response","owner":"bayfrontmedia","description":"Easily send HTTP responses.","archived":false,"fork":false,"pushed_at":"2024-12-26T19:25:06.000Z","size":49,"stargazers_count":6,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-25T16:51:30.691Z","etag":null,"topics":["header","http","method","php","redirect","response","url"],"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/bayfrontmedia.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null}},"created_at":"2020-08-10T17:31:15.000Z","updated_at":"2024-12-26T19:24:41.000Z","dependencies_parsed_at":"2023-02-18T09:45:40.896Z","dependency_job_id":null,"html_url":"https://github.com/bayfrontmedia/php-http-response","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/bayfrontmedia%2Fphp-http-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/bayfrontmedia","download_url":"https://codeload.github.com/bayfrontmedia/php-http-response/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248449899,"owners_count":21105582,"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":["header","http","method","php","redirect","response","url"],"created_at":"2024-11-07T07:22:41.848Z","updated_at":"2025-04-11T17:32:11.375Z","avatar_url":"https://github.com/bayfrontmedia.png","language":"PHP","readme":"## PHP HTTP response\n\nEasily send HTTP responses.\n\n- [License](#license)\n- [Author](#author)\n- [Requirements](#requirements)\n- [Installation](#installation)\n- [Usage](#usage)\n\n## License\n\nThis project is open source and available under the [MIT License](LICENSE).\n\n## Author\n\n\u003cimg src=\"https://cdn1.onbayfront.com/bfm/brand/bfm-logo.svg\" alt=\"Bayfront Media\" width=\"250\" /\u003e\n\n- [Bayfront Media homepage](https://www.bayfrontmedia.com?utm_source=github\u0026amp;utm_medium=direct)\n- [Bayfront Media GitHub](https://github.com/bayfrontmedia)\n\n## Requirements\n\n- PHP `^8.0` (Tested up to `8.4`)\n- JSON PHP extension\n\n## Installation\n\n```\ncomposer require bayfrontmedia/php-http-response\n```\n\n## Usage\n\n- [reset](#reset)\n- [setStatusCode](#setstatuscode)\n- [getStatusCode](#getstatuscode)\n- [removeHeaders](#removeheaders)\n- [setHeaders](#setheaders)\n- [getHeaders](#getheaders)\n- [setBody](#setbody)\n- [getBody](#getbody)\n- [send](#send)\n- [sendJson](#sendjson)\n- [redirect](#redirect)\n\n\u003chr /\u003e\n\n### reset\n\n**Description:**\n\nResets all headers (including status code) and body.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (self)\n\n**Example:**\n\n```\n$response-\u003ereset();\n```\n\n\u003chr /\u003e\n\n### setStatusCode\n\n**Description:**\n\nSets status code to be sent with response.\n\n**Parameters:**\n\n- `$status` (int)\n\n**Returns:**\n\n- (self)\n\n**Throws:**\n\n- `Bayfront\\HttpResponse\\InvalidStatusCodeException`\n\n**Example:**\n\n```\nuse Bayfront\\HttpResponse\\InvalidStatusCodeException;\nuse Bayfront\\HttpResponse\\Response;\n\n$response = new Response();\n\ntry {\n    \n    $response-\u003esetStatusCode(429);\n    \n} catch (InvalidStatusCodeException $e) {\n    die($e-\u003egetMessage());\n}\n```\n\n\u003chr /\u003e\n\n### getStatusCode\n\n**Description:**\n\nReturns the status code and associated phrase to be sent with response.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (array)\n\n**Example:**\n\n```\nprint_r($response-\u003egetStatusCode());\n```\n\n\u003chr /\u003e\n\n### removeHeaders\n\n**Description:**\n\nSets header values to be removed with the response.\n\n**Parameters:**\n\n- `$headers` (array)\n\n**Returns:**\n\n- (self)\n\n**Example:**\n\n```\n$response-\u003eremoveHeaders([\n    'X-Powered-By'\n]);\n```\n\n\u003chr /\u003e\n\n### setHeaders\n\n**Description:**\n\nSets header values to be sent with the response.\n\n**Parameters:**\n\n- `$headers` (array)\n\n**Returns:**\n\n- (self)\n\n**Example:**\n\n```\n$response-\u003esetHeaders([\n    'X-Rate-Limit-Limit' =\u003e 100,\n    'X-Rate-Limit-Remaining' =\u003e 99\n]);\n```\n\n\u003chr /\u003e\n\n### getHeaders\n\n**Description:**\n\nReturns array of headers to be sent with the response.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (array)\n\n**Example:**\n\n```\nprint_r($response-\u003egetHeaders());\n```\n\n\u003chr /\u003e\n\n### setBody\n\n**Description:**\n\nSets body to be sent with the response.\n\n**Parameters:**\n\n- `$body` (string)\n\n**Returns:**\n\n- (self)\n\n**Example:**\n\n```\n$response-\u003esetBody('This is the response body.');\n```\n\n\u003chr /\u003e\n\n### getBody\n\n**Description:**\n\nReturns body to be sent with the response.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (string)\n\n**Example:**\n\n```\necho $response-\u003egetBody();\n```\n\n\u003chr /\u003e\n\n### send\n\n**Description:**\n\nSends response.\n\n**Parameters:**\n\n- None\n\n**Returns:**\n\n- (void)\n\n**Example:**\n\n```\n$response-\u003esend();\n```\n\n\u003chr /\u003e\n\n### sendJson\n\n**Description:**\n\nSets Content-Type as `application/json`, and converts the given array to the JSON encoded body.\n\n**Parameters:**\n\n- `$array` (array)\n\n**Returns:**\n\n- (void)\n\n**Example:**\n\n```\n$response-\u003esendJson([\n    'results' =\u003e [\n        'user_id' =\u003e 5,\n        'username' =\u003e 'some_username'\n    ],\n    'status' =\u003e 'OK'\n]);\n```\n\n\u003chr /\u003e\n\n### redirect\n\n**Description:**\n\nRedirects to a given URL using a given status code.\n\n**Parameters:**\n\n- `$url` (string)\n- `$status = 302` (int): HTTP status code to return\n\n**Returns:**\n\n- (void)\n\n**Throws:**\n\n- `Bayfront\\HttpResponse\\InvalidStatusCodeException`\n\n**Example:**\n\n```\nuse Bayfront\\HttpResponse\\InvalidStatusCodeException;\nuse Bayfront\\HttpResponse\\Response;\n\n$response = new Response();\n\ntry {\n\n    $response-\u003eredirect('https://www.google.com', 301);\n\n} catch (InvalidStatusCodeException $e) {\n    die($e-\u003egetMessage());\n}\n```","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-http-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbayfrontmedia%2Fphp-http-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbayfrontmedia%2Fphp-http-response/lists"}