{"id":15019871,"url":"https://github.com/ftd-educacao/default-api-response","last_synced_at":"2026-01-21T01:03:00.697Z","repository":{"id":62507788,"uuid":"97644613","full_name":"ftd-educacao/default-api-response","owner":"ftd-educacao","description":"This package was created to extend the Laravel Framework response system","archived":false,"fork":false,"pushed_at":"2017-07-18T22:07:55.000Z","size":31,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-05-10T11:48:09.981Z","etag":null,"topics":["api","api-wrapper","apirest","apirestfull","jsonapi","laravel","laravel-5-package","laravel-package","laravel5","laravel5-package","padronization","rest-api","restful","restful-api"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ftd-educacao.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":"2017-07-18T21:15:14.000Z","updated_at":"2017-07-19T16:14:05.000Z","dependencies_parsed_at":"2022-11-02T12:46:09.064Z","dependency_job_id":null,"html_url":"https://github.com/ftd-educacao/default-api-response","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/ftd-educacao/default-api-response","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ftd-educacao%2Fdefault-api-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ftd-educacao%2Fdefault-api-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ftd-educacao%2Fdefault-api-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ftd-educacao%2Fdefault-api-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ftd-educacao","download_url":"https://codeload.github.com/ftd-educacao/default-api-response/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ftd-educacao%2Fdefault-api-response/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28620572,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-20T23:49:58.628Z","status":"ssl_error","status_checked_at":"2026-01-20T23:47:29.996Z","response_time":117,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["api","api-wrapper","apirest","apirestfull","jsonapi","laravel","laravel-5-package","laravel-package","laravel5","laravel5-package","padronization","rest-api","restful","restful-api"],"created_at":"2024-09-24T19:54:13.284Z","updated_at":"2026-01-21T01:03:00.675Z","avatar_url":"https://github.com/ftd-educacao.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003cimg src=\"https://github.com/ftd-educacao/default-api-response/blob/master/docs/ftd-default-api-response-logo.png?raw=true\" alt=\"FTD Default API Response\"\u003e\u003c/p\u003e\n\nWelcome to FTD Default API Response!\n===================\n\n- About\n- Installation\n- How to use\n  - **The success method**\n  - **The paginate method**\n  - **The error method**\n  - **Advanced use for the success, paginate and error methods**\n  - **The custom method**\n  - **The defaultStatusCode method**\n  - **The code list for defaultStatusCode method**\n\n\n----------\n\n\nAbout\n=====\nThis package was created to extend the **Laravel Framework** response system, and elevate him to the standard described on the [**{json:api}**](http://jsonapi.org) website[^jsonapi].\n\nThe answers besides creating a more friendly and readable formatting also contemplate the control of the Headers according to the last code.\n\n\n----------\n\n\nInstallation\n=====\nUse composer do install our package:\n\n```bash\ncomposer require ftd-educacao/default-api-response\n```\n\nAnd call the provider inside your Laravel **/config/app.php** file:\n\n```php\n    'providers' =\u003e [\n    ...\n        /*\n         * FTD Default API Response\n         */\n         FTD\\DefaultApiResponse\\DefaultApiResponseServiceProvider::class,\n    ],\n```\n\nNow it's done and we're ready to go!\n\n\n----------\n\n\nHow to use\n=====\n\n**FTD API Response** give us 5 new methods:\n\n 1. success\n 2. paginate\n 3. error\n 4. custom\n 5. defaultStatusCode\n\nEvery method has a particular way to use, but always easy.\n\n**The success method**\n----------------------\n\nThis method will throw a header status code **200** and put your content inside a **data** wrapper:\n\n**Example:**\n```php\n  public function index()\n  {\n      return response()-\u003esuccess(App\\User::all());\n  }\n```\n\n**Result:**\n```json\n{\n  \"data\": [\n    {\n      \"id\": 1,\n      \"name\": \"Rodolfo\",\n      \"email\": \"rodolfo@ftdapi.com\",\n      \"created_at\": null,\n      \"updated_at\": null\n    },\n    {\n      \"id\": 2,\n      \"name\": \"Shirley\",\n      \"email\": \"shirlei@ftdapi.com\",\n      \"created_at\": \"2017-06-16 01:02:03\",\n      \"updated_at\": null\n    }\n  ]\n}\n```\n\n\n**Example:**\n```php\n  public function show(User $user)\n  {\n      return response()-\u003esuccess($user);\n  }\n```\n\n**Result:**\n```json\n{\n  \"data\": {\n    \"id\": 1,\n    \"name\": \"Rodolfo\",\n    \"email\": \"rodolfo@ftdapi.com\",\n    \"created_at\": null,\n    \"updated_at\": null\n  }\n}\n```\n\n**The paginate method**\n----------------------\nThis method will throw a header status code **200** and put your content inside a **data** wrapper, and create another wrapper called **meta**, for the pagination properties:\n\n**Example:**\n```php\n  public function index()\n  {\n      $users = App\\User::paginate(2);\n    return response()-\u003epaginate($users);\n  }\n```\n\n**Result:**\n```json\n{\n  \"meta\": {\n    \"pagination\": {\n      \"current_page\": 2,\n      \"from\": 3,\n      \"last_page\": 3,\n      \"next_page_url\": \"http://ftdapi.com/api?page=3\",\n      \"path\": \"http://ftdapi.com/api\",\n      \"per_page\": 2,\n      \"prev_page_url\": \"http://ftdapi.com/api?page=1\",\n      \"to\": 4,\n      \"total\": 6\n    }\n  },\n  \"data\": [\n    {\n      \"id\": 3,\n      \"name\": \"Marley\",\n      \"email\": \"marley@ftdapi.com\",\n      \"created_at\": \"2017-06-15 00:00:01\",\n      \"updated_at\": null\n    },\n    {\n      \"id\": 4,\n      \"name\": \"Steve\",\n      \"email\": \"steve@ftdapi.com\",\n      \"created_at\": \"2017-06-16 01:02:03\",\n      \"updated_at\": null\n    }\n  ]\n}\n```\n\n\n**The error method**\n----------------------\nThis method will throw a header status code **400** and put your content inside a **errors** wrapper:\n\n**Example:**\n```php\n  //User Custom Request\n  public function rules()\n  {\n    return [\n        'name'      =\u003e 'required|string|max:255',\n        'username'  =\u003e 'required|unique:users|string|max:255',\n        'password'  =\u003e 'required|string|max:255'\n    ];\n  }\n\n  ...\n\n  public function response(array $errors)\n  {\n    return response()-\u003eerror($errors);\n  }\n```\n\n**Result:**\n```json\n{\n  \"errors\": [\n    \"Name must be provided.\",\n    \"Username must be provided.\",\n    \"Password must be provided.\"\n  ]\n}\n```\n\n\n**Advanced use for the success, paginate and error methods**\n----------------------\n\nIf you need change the default status code of this methods, you can give a second parameter, like:\n\n```php\n  ...\n  return response()-\u003esuccess($data, 201);\n\n  ...\n  return response()-\u003epaginate($data, 206);\n\n  ...\n  return response()-\u003eerror($data, 401);\n\n```\n\n\n**The custom method**\n----------------------\nThis method is used for who need more control of the entire response:\n\n - The default **content** is **null**\n - The default **header status code** is **200**\n - The default **extra headers** is **null**\n - The default **header content type** is **'application/json'**\n\n\n\n**Example:**\n```php\n  public function myCustomMethod()\n  {\n    return response()-\u003ecustom(\n      $content = [\n            \"Name\" =\u003e \"Rodolfo\",\n            \"Age\"=\u003e13\n            ],\n      $status = 200,\n      $headers = [\"X-USER-INFO\" =\u003e TRUE],\n      $headerContentType = 'application/json'\n    );\n  }\n```\n\n**Result:**\nIn your header you will see the:\n\n```bash\n  \"X-USER-INFO\" : true\n```\n\nor\n\n```bash\n  \"X-USER-INFO\" : 1\n```\n\nDepends on which browser you are using.\n\nAnd, finally, the response body will receive the contents, but **without** the default **data** wrapper:\n```json\n{\n  \"Name\": \"Rodolfo\",\n  \"Age\": 13\n}\n```\n\nIf you need to force download of a PDF file, for example, this method is the right way to do it.\n\n**The defaultStatusCode method**\n----------------------\n\nThis method will throw a header status code and depends on which code, put default message content inside a **data** or **errors** wrapper:\n\n**Example:**\n```php\n  public function store()\n  {\n    return response()-\u003edefaultStatusCode(400);\n  }\n```\n\n**Result:**\n```json\n{\n  \"errors\": [\n    \"Bad Request\"\n  ]\n}\n```\n\n**The code list for defaultStatusCode method**\n-------------\n\n|Code | Reference               |\n|-----|-------------------------------------|\n| 102 | 'Processing',           |\n| 200 | 'OK',               |\n| 201 | 'Created',              |\n| 202 | 'Accepted',             |\n| 203 | 'Non-authoritative Information',  |\n| 204 | '',//No Content           |\n| 206 | 'Partial Content',          |\n| 207 | 'Multi-Status',           |\n| 302 | 'Found',              |\n| 304 | 'Not Modified',           |\n| 400 | 'Bad Request',            |\n| 401 | 'Unauthorized',           |\n| 402 | 'Payment Required',         |\n| 403 | 'Forbidden',            |\n| 404 | 'Not Found',            |\n| 405 | 'Method Not Allowed',       |\n| 406 | 'Not Acceptable',         |\n| 409 | 'Conflict',             |\n| 413 | 'Payload Too Large',        |\n| 415 | 'Unsupported Media Type',     |\n| 416 | 'Requested Range Not Satisfiable',  |\n| 422 | 'Unprocessable Entity',       |\n| 423 | 'Locked',             |\n| 424 | 'Failed Dependency',        |\n| 500 | 'Internal Server Error',      |\n| 501 | 'Not Implemented',          |\n| 503 | 'Service Unavailable'       |\n\n\n----------\n\n\nIf you need more information about status code, the [HTTP Status Codes](https://httpstatuses.com/) website[^statuscodes] may help you.\n\n\n\n[^jsonapi]: **{json:api}** A specification for building apis in json.\n\n[^statuscodes]: **httpstatuses.com** is an easy to reference database of HTTP Status Codes with their definitions and helpful code references all in one place.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fftd-educacao%2Fdefault-api-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fftd-educacao%2Fdefault-api-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fftd-educacao%2Fdefault-api-response/lists"}