{"id":22030942,"url":"https://github.com/nnjeim/respond","last_synced_at":"2025-08-02T20:32:59.946Z","repository":{"id":57027828,"uuid":"405552428","full_name":"nnjeim/respond","owner":"nnjeim","description":"Laravel response wrapper","archived":false,"fork":false,"pushed_at":"2021-09-20T06:21:00.000Z","size":20,"stargazers_count":5,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-07-26T02:55:05.374Z","etag":null,"topics":["json-api","laravel","laravel-package","package","response"],"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/nnjeim.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-09-12T05:10:15.000Z","updated_at":"2021-11-02T16:08:19.000Z","dependencies_parsed_at":"2022-08-23T16:30:12.557Z","dependency_job_id":null,"html_url":"https://github.com/nnjeim/respond","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"purl":"pkg:github/nnjeim/respond","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnjeim%2Frespond","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnjeim%2Frespond/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnjeim%2Frespond/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnjeim%2Frespond/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/nnjeim","download_url":"https://codeload.github.com/nnjeim/respond/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/nnjeim%2Frespond/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":268448362,"owners_count":24252019,"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-08-02T02:00:12.353Z","response_time":74,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","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":["json-api","laravel","laravel-package","package","response"],"created_at":"2024-11-30T08:12:30.903Z","updated_at":"2025-08-02T20:32:59.903Z","avatar_url":"https://github.com/nnjeim.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n\u003cp\u003e\u003cimg src=\"https://eu.ui-avatars.com/api/?name=Najm+Njeim?size=100\" width=\"100\"/\u003e\u003c/p\u003e  \n\nA Laravel response helper methods. The package `respond` provides a fluent syntax to form array or json responses.  \nIn its configuration file, it allows the addition of custom methods.\n\n## Installation\n\nYou can install the package via composer:\n```\ncomposer require nnjeim/respond\n```\n\n## Configuration\n```\nphp artisan vendor:publish --provider=\"Nnjeim\\Respond\\RespondServiceProvider\"\n```\n\nThe `respond.php` config file allows:   \n- The presetting of the response format array/json.\n- The possibility to edit the response parameters.\n- The possibility to add custom methods.\n\n## Usage\n\n##### Respond Facade\n``` \nuse Nnjeim\\Fetch\\Fetch;\nuse Nnjeim\\Respond\\Respond;\n\n['response' =\u003e $response, 'status' =\u003e $status] = Fetch::setBaseUri('https://someapi.com/')-\u003eget('countries');\n\n\tif ($status === 200 \u0026\u0026 $response-\u003esuccess) {\n\n\t\treturn Respond::toJson()\n\t\t\t-\u003esetMessage('countries')\n\t\t\t-\u003esetData($response-\u003edata)\n\t\t\t-\u003ewithSuccess();\n\t}\n\n\tabort(400);\n```\n##### RespondHelper Instantiation\n\n```\nuse Nnjeim\\Respond\\RespondHelper;\n\nprivate RespondHelper $respond;\nprivate array $data;\nprivate bool $success;\n\npublic function __construct(RespondHelper $respond)\n{\n\t$this-\u003erespond = $respond;\n}\n.\n.\n.\n$respond = $this\n\t\t-\u003erespond\n\t\t-\u003etoJson()\n\t\t-\u003esetMessage('countries')\n\t\t-\u003esetData($data);\n\nif ($this-\u003esuccess)\n{\n\treturn $respond-\u003ewithSuccess()\n}\n\nreturn $respond-\u003ewithErrors();\n```\n\n## Methods\n\n##### Set the status code\n```\nSets the response status code  \n\n@return $this       setStatusCode(int $statusCode)\n```\n\n##### Set the message\n```\nSets the response title message\n\n@return $this       setMessage(string $message)\n```\n\n##### Set the meta data\n```\nSets the response meta data. The meta data will be merged with the response data array.\n\n@return $this       setMeta(array $meta)\n```\n\n##### Set the data\n```\nSets the response data array.\n\n@return $this       setData(array $data)\n```\n\n##### Set the errors\n```\nSets the response errors.\n\n@return $this       setErrors(array $errors)\n```\n\n##### respond in Json format\n```\nreturns an instance of Illuminate\\Http\\JsonResponse  \n\nthis method overwrites the config `toJson` set value.\n\n@return $this       toJson()\n```\n\n##### Respond with success\n```\nOn success response. The default response status code is 200.   \n\n@return array|JsonResponse       withSuccess()\n```\n\n##### Respond with created\n```\nOn created response. The default response status code is 201.   \n\n@return array|JsonResponse       withCreated()\n```\n\n##### Respond with accepted\n```\nOn accepted response. The default response status code is 202.   \n\n@return array|JsonResponse       withAccepted()\n```\n\n##### Respond with no content\n```\nOn success response with no results found. The default status code is 204\n\n@return array|JsonResponse       withNoContent()\n```\n\n#####  Respond with errors\n```\nOn error response. The default response status code is 422.   \n\n@return array|JsonResponse       withErrors(?array $errors = null)\n```\n\n##### Respond with server error\n```\nOn server error response. The default response status code is 500.   \n\n@return array|JsonResponse       withServerError()       \n```\n\n##### Respond with not found\n```\nRecord not found error. The default response status code is 404.\n\n@return array|JsonResponse       withNotFound()\n```\n\n##### Respond with not authenticated\n```\nNot authenticated reponse. The default response status code is 401.\n\n@return array|JsonResponse       withNotAuthenticated()\n```\n\n##### Respond with not authorized\n```\nNot authorized reponse. The default response status code is 403.\n\n@return array|JsonResponse       withNotAuthorized()\n```\n\n## Respond\n\n```\n@return array|JsonResponse\n\n\t[\n\t\t'response' =\u003e [\n\t\t\t'success' =\u003e true,\n\t\t\t'message' =\u003e 'message',\n\t\t\t'data' =\u003e [],\n\t\t\t'errors' =\u003e [],\n\t\t],\n\t\t'status' =\u003e 200,\n\t];\n```\n\n## Custom methods\n\nIn the `respond.php` config file, in the responses array add an array entry where the key is name of the method in lower \ncase and the value contains the desired success, message and status params.\n\n```\n//example\n'methodnotallowed' =\u003e [\n    'success' =\u003e false,\n    'message' =\u003e 'the method not allowed!',\n    'status' =\u003e Response::HTTP_METHOD_NOT_ALLOWED,\n],\n```\n\n#### Usage\n\n`Respond::withMethodNotAllowed();`\n\n## Testing\n\nThe helpers and methods are tested with 99% coverage.  \nTo run the tests.  \n``` bash\ncomposer install\ncomposer test\n```\n\nTo run the coverage test.\n``` bash\ncomposer test-coverage\n```\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information what has changed recently.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnjeim%2Frespond","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnnjeim%2Frespond","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnnjeim%2Frespond/lists"}