{"id":29112763,"url":"https://github.com/adnan-kamili/rest-api-response-format","last_synced_at":"2025-06-29T11:03:15.292Z","repository":{"id":40617440,"uuid":"64393183","full_name":"adnan-kamili/rest-api-response-format","owner":"adnan-kamili","description":"REST API response format using HTTP status codes","archived":false,"fork":false,"pushed_at":"2017-08-30T11:15:45.000Z","size":15,"stargazers_count":501,"open_issues_count":0,"forks_count":118,"subscribers_count":14,"default_branch":"master","last_synced_at":"2025-06-24T14:13:46.273Z","etag":null,"topics":["rest","rest-api","restapi","restful"],"latest_commit_sha":null,"homepage":"","language":null,"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/adnan-kamili.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":"2016-07-28T12:20:55.000Z","updated_at":"2025-06-01T18:27:17.000Z","dependencies_parsed_at":"2022-07-20T13:47:48.714Z","dependency_job_id":null,"html_url":"https://github.com/adnan-kamili/rest-api-response-format","commit_stats":null,"previous_names":["adnan-kamili/rest-api-response-format"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/adnan-kamili/rest-api-response-format","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnan-kamili%2Frest-api-response-format","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnan-kamili%2Frest-api-response-format/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnan-kamili%2Frest-api-response-format/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnan-kamili%2Frest-api-response-format/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/adnan-kamili","download_url":"https://codeload.github.com/adnan-kamili/rest-api-response-format/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/adnan-kamili%2Frest-api-response-format/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":262581282,"owners_count":23331908,"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":["rest","rest-api","restapi","restful"],"created_at":"2025-06-29T11:03:14.610Z","updated_at":"2025-06-29T11:03:15.276Z","avatar_url":"https://github.com/adnan-kamili.png","language":null,"funding_links":[],"categories":[],"sub_categories":[],"readme":"# rest-api-response-format\nREST API response format based on some of the best practices\n\nThe **swagger.yaml** file for following sample responses is available at:\n\nhttps://github.com/adnan-kamili/swagger-sample-template\n\n## Rest API Popular Endpoint Formats\n\n\u003e https://api.example.com/v1/items\n\n\u003e https://example.com/api/v1/items\n\n## Rest API Success Responses\n\n1- GET - Get single item - HTTP Response Code: **200**\n```javascript\n    HTTP/1.1 200\n    Content-Type: application/json\n\n    {\n        \"id\": 10,\n        \"name\": \"shirt\",\n        \"color\": \"red\",\n        \"price\": \"$23\"\n    }\n```\n2- GET - Get item list - HTTP Response Code: **200**\n```javascript\n    HTTP/1.1 200\n    Pagination-Count: 100\n    Pagination-Page: 5\n    Pagination-Limit: 20\n    Content-Type: application/json\n    \n    [\n      {\n        \"id\": 10,\n        \"name\": \"shirt\",\n        \"color\": \"red\",\n        \"price\": \"$123\"\n      },\n      {\n        \"id\": 11,\n        \"name\": \"coat\",\n        \"color\": \"black\",\n        \"price\": \"$2300\"\n      }\n    ]\n```\n\n3- POST - Create a new item - HTTP Response Code: **201**\n```javascript\n    HTTP/1.1  201\n    Location: /v1/items/12\n    Content-Type: application/json\n \n    {\n      \"message\": \"The item was created successfully\"\n    }\n```\n4- PATCH - Update an item - HTTP Response Code: **200/204** \n\n\u003e If updated entity is to be sent after the update\n\n```javascript\n    HTTP/1.1  200\n    Content-Type: application/json\n \n    {\n        \"id\": 10,\n        \"name\": \"shirt\",\n        \"color\": \"red\",\n        \"price\": \"$23\"\n    }\n```\n\n\u003e If updated entity is not to be sent after the update\n\n```javascript\n    HTTP/1.1  204\n```\n\n5- DELETE - Delete an item - HTTP Response Code: **204**\n```javascript\n    HTTP/1.1  204\n```\n\n\n## Rest API Error Responses\n\n1- GET - HTTP Response Code: **404**\n\n```javascript\n    HTTP/1.1  404\n    Content-Type: application/json\n \n    {\n      \"message\": \"The item does not exist\"\n    }\n```\n2- DELETE - HTTP Response Code: **404**\n```javascript\n    HTTP/1.1  404\n    Content-Type: application/json\n \n    {\n      \"message\": \"The item does not exist\"\n    }\n```\n3- POST -  HTTP Response Code: **400**\n```javascript\n    HTTP/1.1  400\n    Content-Type: application/json\n    \n    {\n        \"message\": \"Validation errors in your request\", /* skip or optional error message */\n        \"errors\": [\n            {\n                \"message\": \"Oops! The value is invalid\",\n                \"code\": 34,\n                \"field\": \"email\"\n            },\n            {\n                \"message\": \"Oops! The format is not correct\",\n                \"code\": 35,\n                \"field\": \"phoneNumber\"\n            }\n        ]\n    }\n```\n4- PATCH -  HTTP Response Code: **400/404**\n```javascript\n    HTTP/1.1  400\n    Content-Type: application/json\n    \n    {\n        \"message\": \"Validation errors in your request\", /* skip or optional error message */\n        \"errors\": [\n            {\n                \"message\": \"Oops! The format is not correct\",\n                \"code\": 35,\n                \"field\": \"phoneNumber\"\n            }\n        ]\n    }\n    \n    \n    HTTP/1.1  404\n    Content-Type: application/json\n \n    {\n      \"message\": \"The item does not exist\"\n    }\n```\n5- VERB Unauthorized - HTTP Response Code: **401**\n```javascript\n    HTTP/1.1  401\n    Content-Type: application/json\n \n    {\n      \"message\": \"Authentication credentials were missing or incorrect\"\n    }\n```\n6- VERB Forbidden - HTTP Response Code: **403**\n```javascript\n    HTTP/1.1  403\n    Content-Type: application/json\n \n    {\n      \"message\": \"The request is understood, but it has been refused or access is not allowed\"\n    }\n```\n7- VERB Conflict - HTTP Response Code: **409**\n```javascript\n    HTTP/1.1  409\n    Content-Type: application/json\n \n    {\n      \"message\": \"Any message which should help the user to resolve the conflict\"\n    }\n```\n8- VERB Too Many Requests - HTTP Response Code: **429**\n```javascript\n    HTTP/1.1  429\n    Content-Type: application/json\n \n    {\n      \"message\": \"The request cannot be served due to the rate limit having been exhausted for the resource\"\n    }\n```\n9- VERB Internal Server Error - HTTP Response Code: **500**\n```javascript\n    HTTP/1.1  500\n    Content-Type: application/json\n \n    {\n      \"message\": \"Something is broken\"\n    }\n```\n10- VERB Service Unavailable - HTTP Response Code: **503**\n```javascript\n    HTTP/1.1  503\n    Content-Type: application/json\n \n    {\n      \"message\": \"The server is up, but overloaded with requests. Try again later!\"\n    }\n```\n## Validation Error Formats\n\nValidation error formats can be different depending on your requirements. Following are some other popular formats, other than the one used above.\n\n```javascript\n    HTTP/1.1  400\n    Content-Type: application/json\n    \n    {\n        \"message\": \"Validation errors in your request\", /* skip or optional error message */\n        \"errors\": {\n            \"email\": [\n                  \"Oops! The email is invalid\"\n                ],\n            \"phoneNumber\": [\n                  \"Oops! The phone number format is not correct\"\n                ]\n        }\n    }\n```\n```javascript\n    HTTP/1.1  400\n    Content-Type: application/json\n    \n    {\n        \"message\": \"Validation errors in your request\", /* skip or optional error message */\n        \"errors\": {\n            \"email\": [\n              {\n                \"message\": \"Oops! The email is invalid\",\n                \"code\": 35\n              }\n            ],\n            \"phoneNumber\": [\n              {\n                \"message\": \"Oops! The phone number format is not correct\",\n                \"code\": 36\n              }\n            ]\n        }\n    }\n```\n\n## References\nPATCH with partial json can be used for updating the resource: https://tools.ietf.org/html/rfc7396\n\nAvoid using 'X-' in custom headers: https://tools.ietf.org/html/rfc6648\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadnan-kamili%2Frest-api-response-format","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fadnan-kamili%2Frest-api-response-format","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fadnan-kamili%2Frest-api-response-format/lists"}