{"id":15106042,"url":"https://github.com/mrgarest/echo-api","last_synced_at":"2025-10-20T08:38:14.422Z","repository":{"id":257779011,"uuid":"859806417","full_name":"mrgarest/echo-api","owner":"mrgarest","description":"A simple package for generating API responses in Laravel","archived":false,"fork":false,"pushed_at":"2024-12-01T20:35:37.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-01-30T16:43:26.392Z","etag":null,"topics":["api","json","laravel","laravel-package","php"],"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/mrgarest.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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":"2024-09-19T10:05:48.000Z","updated_at":"2024-12-01T20:34:07.000Z","dependencies_parsed_at":"2024-09-25T21:00:37.402Z","dependency_job_id":null,"html_url":"https://github.com/mrgarest/echo-api","commit_stats":null,"previous_names":["mrgarest/echo-api"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Fecho-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Fecho-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Fecho-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mrgarest%2Fecho-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mrgarest","download_url":"https://codeload.github.com/mrgarest/echo-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":237759101,"owners_count":19361458,"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":["api","json","laravel","laravel-package","php"],"created_at":"2024-09-25T21:00:34.482Z","updated_at":"2025-10-20T08:38:09.389Z","avatar_url":"https://github.com/mrgarest.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EchoApi\n\nA simple package for generating API responses in Laravel.\n\n## Installation\n\nYou can install the package via composer:\n\n```\ncomposer require mrgarest/echo-api\n```\n\n# Examples\n\nBelow are some examples using the methods for different responses.\n\n## Success\n\nTo create a successful JSON response, you can use the method:\n\n```php\nreturn EchoApi::success();\n```\n\nResponse result:\n\n```json\n{\n  \"success\": true\n}\n```\n\n### Adding additional data\n\nIf you want to add additional data to the response, you can pass an array with data to the `success()` method.\n\n```php\n$data = [\n    'user' =\u003e [\n        'id' =\u003e 21314,\n        'role' =\u003e 'user',\n        'email' =\u003e 'email@example.com'\n    ]\n];\n\nreturn EchoApi::success($data);\n```\n\nResponse result:\n\n```json\n{\n  \"success\": true,\n  \"user\": {\n    \"id\": 21314,\n    \"role\": \"user\",\n    \"email\": \"email@example.com\"\n  }\n}\n```\n\n## Error\n\nTo create a JSON response with the HTTP error code, you can use the method:\n\n```php\n$httpStatus = Response::HTTP_NOT_FOUND; // 404 Not Found\nreturn EchoApi::httpError($httpStatus);\n```\n\nResponse result:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": 404,\n    \"message\": \"Bad Request\"\n  }\n}\n```\n\n### Custom error\n\nIf the standard HTTP error codes are not enough for you, you can use your own by creating them in the `config/echo-api.php` file.\n\n```php\nreturn EchoApi::findError('EXAMPLE');\n```\n\nResponse result:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": \"EXAMPLE\",\n    \"message\": \"Example of error data structure\"\n  }\n}\n```\n\n*To get `echo-api.php`, don't forget to run `php artisan vendor:publish`.*\n\n### Adding additional data\n\nAs with the `success()` method, you can add additional data to the responses for the `httpError()` and `findError()` methods.\n\n```php\n$data = [\n    'error' = [\n        'uuid' =\u003e '21e38f4d-3be8-457c-98da-3059a947e75b'\n    ],\n    'count' =\u003e 0,\n    'data' =\u003e null\n];\nreturn EchoApi::httpError(Response::HTTP_NOT_FOUND, $data);\n```\n\nResponse result:\n\n```json\n{\n  \"success\": false,\n  \"error\": {\n    \"code\": 404,\n    \"message\": \"Bad Request\",\n    \"uuid\": \"21e38f4d-3be8-457c-98da-3059a947e75b\"\n  },\n  \"count\": 0,\n  \"data\": null\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgarest%2Fecho-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmrgarest%2Fecho-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmrgarest%2Fecho-api/lists"}