{"id":16462586,"url":"https://github.com/sametsahindogan/response-object-creator","last_synced_at":"2025-07-01T09:35:13.577Z","repository":{"id":62539787,"uuid":"235332495","full_name":"sametsahindogan/response-object-creator","owner":"sametsahindogan","description":"Provide to standardized response objects for your API.","archived":false,"fork":false,"pushed_at":"2020-01-21T12:19:51.000Z","size":4,"stargazers_count":6,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T11:11:41.590Z","etag":null,"topics":["json","rest-api"],"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/sametsahindogan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-21T12:00:46.000Z","updated_at":"2023-09-09T21:07:01.000Z","dependencies_parsed_at":"2022-11-02T15:32:08.539Z","dependency_job_id":null,"html_url":"https://github.com/sametsahindogan/response-object-creator","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fresponse-object-creator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fresponse-object-creator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fresponse-object-creator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sametsahindogan%2Fresponse-object-creator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sametsahindogan","download_url":"https://codeload.github.com/sametsahindogan/response-object-creator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221849565,"owners_count":16891490,"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":["json","rest-api"],"created_at":"2024-10-11T11:11:43.993Z","updated_at":"2024-10-28T15:37:20.438Z","avatar_url":"https://github.com/sametsahindogan.png","language":"PHP","readme":"# response-object-creator\n\n[![GitHub license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](https://raw.githubusercontent.com/sametsahindogan/response-object-creator/master/LICENSE)\n\n\u003eThis package provides to standardized response objects for your API.\n\n\u003ca\u003e\u003cimg src=\"https://upload.wikimedia.org/wikipedia/commons/thumb/6/6a/Nullset.svg/1200px-Nullset.svg.png\" width=\"80\"\u003e\u003c/a\u003e\n\n\u003eOne of the important things in an API is that it has a standard response type. This package provides a standard response structure for your API.\n\n## Installation\n```bash\ncomposer require sametsahindogan/response-object-creator\n```\n## Usage\n\n**If you want to return a \"success\" result;**\n```php\n// Your array that you want to return as an object. \n $data = [\n        'id' =\u003e 1,\n        'name' =\u003e 'John',\n        'surname' =\u003e 'Doe'\n    ];\n\n// If you use pure PHP;\n return json_encode( new SuccessResult($data) );\n    \n// If you use Laravel Framework;\n return response()-\u003ejson( new SuccessResult($data) );\n\n// If you use Symfony Framework;\n return new JsonResponse( new SuccessResult($data) );\n```\nOutput;\n```json\n{\n      \"success\": true,\n      \"data\": {\n          \"id\": 1,\n          \"name\": \"John\",\n          \"surname\": \"Doe\"\n      }\n}\n```\n**If you want to return an \"error\" result;**\n```php\n// You must create an Error Builder object.\n $errorBuilder = new ErrorBuilder();\n\n// If you use pure PHP;\n  return json_encode(new ErrorResult(\n             $errorBuilder-\u003etitle('Error')\n                 -\u003emessage('Something wrong happened.')\n                 -\u003ecode(1)\n                 -\u003eextra(['You can add some extra messages or etc.'])\n         )\n     );\n    \n// If you use Laravel Framework;\n return response()-\u003ejson(new ErrorResult(\n             $errorBuilder-\u003etitle('Error')\n                 -\u003emessage('Something wrong happened.')\n                 -\u003ecode(1)\n                 -\u003eextra(['You can add some extra messages or etc.'])\n         )\n     );\n\n// If you use Symfony Framework;\n return new JsonResponse(new ErrorResult(\n             $errorBuilder-\u003etitle('Error')\n                 -\u003emessage('Something wrong happened.')\n                 -\u003ecode(1)\n                 -\u003eextra(['You can add some extra messages or etc.'])\n         )\n     );\n```\nOutput;\n```json\n{\n      \"success\": false,\n      \"data\": {\n          \"message\": \"User does not have the right roles or permissions.\",\n          \"title\": \"Operation Failed\",\n          \"code\": 1,\n          \"extra\": [ \n               \"You can add some extra messages or etc.\"\n          ]\n      }\n}\n```\n## License\nMIT © [Samet Sahindogan](https://github.com/sametsahindogan/laravel-jwtredis/blob/master/LICENSE)\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsametsahindogan%2Fresponse-object-creator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsametsahindogan%2Fresponse-object-creator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsametsahindogan%2Fresponse-object-creator/lists"}