{"id":15284516,"url":"https://github.com/klaby/http-handler-response","last_synced_at":"2025-10-07T00:32:06.479Z","repository":{"id":56053469,"uuid":"245547470","full_name":"klaby/http-handler-response","owner":"klaby","description":"📨 A simple response handler for HTTP requests","archived":true,"fork":false,"pushed_at":"2020-11-28T13:44:04.000Z","size":667,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-08-09T08:19:40.386Z","etag":null,"topics":["adonisjs","api","expressjs","http","http-status-code","koajs","nodejs","rfc7807"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/klaby.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-03-07T01:24:41.000Z","updated_at":"2023-01-28T09:25:49.000Z","dependencies_parsed_at":"2022-08-15T12:20:12.839Z","dependency_job_id":null,"html_url":"https://github.com/klaby/http-handler-response","commit_stats":null,"previous_names":["hiukky/http-handler-response"],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/klaby/http-handler-response","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaby%2Fhttp-handler-response","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaby%2Fhttp-handler-response/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaby%2Fhttp-handler-response/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaby%2Fhttp-handler-response/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/klaby","download_url":"https://codeload.github.com/klaby/http-handler-response/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/klaby%2Fhttp-handler-response/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278703582,"owners_count":26031204,"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-10-06T02:00:05.630Z","response_time":65,"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":["adonisjs","api","expressjs","http","http-status-code","koajs","nodejs","rfc7807"],"created_at":"2024-09-30T14:57:49.230Z","updated_at":"2025-10-07T00:32:06.141Z","avatar_url":"https://github.com/klaby.png","language":"TypeScript","readme":"\u003ch1 align=\"center\"\u003e http-handler-response \u003c/h1\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://travis-ci.org/github/hiukky/http-handler-response\"\u003e\n    \u003cimg alt=\"Build\" src=\"https://img.shields.io/github/workflow/status/hiukky/http-handler-response/build?color=%2323d18c\u0026style=for-the-badge\u0026colorA=1C1D27\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/hiukky/http-handler-response/stargazers\"\u003e\n    \u003cimg alt=\"GitHub stars\" src=\"https://img.shields.io/github/stars/hiukky/http-handler-response?color=%2300cecb\u0026style=for-the-badge\u0026colorA=1C1D27\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/hiukky/http-handler-response/network\"\u003e\n    \u003cimg alt=\"GitHub forks\" src=\"https://img.shields.io/github/forks/hiukky/http-handler-response?color=%23a29bfe\u0026style=for-the-badge\u0026colorA=1C1D27\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/hiukky/http-handler-response/issues\"\u003e\n    \u003cimg alt=\"GitHub issues\" src=\"https://img.shields.io/github/issues/hiukky/http-handler-response?style=for-the-badge\u0026color=ffe066\u0026colorA=1C1D27\"\u003e\n  \u003c/a\u003e\n   \u003ca href=\"https://github.com/hiukky/http-handler-response/blob/develop/LICENSE\"\u003e\n    \u003cimg alt=\"GitHub license\" src=\"https://img.shields.io/github/license/hiukky/http-handler-response?color=%23eab464\u0026style=for-the-badge\u0026colorA=1C1D27\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/http-handler-response\"\u003e\n    \u003cimg alt=\"NPM\" src=\"https://img.shields.io/npm/dt/http-handler-response?color=%23f49e4c\u0026style=for-the-badge\u0026colorA=1C1D27\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003csub\u003eBuilt with ❤︎ by \u003ca href=\"https://hiukky.com\"\u003eHiukky\u003c/a\u003e\n  \u003cbr/\u003e\n\u003c/p\u003e\n\n  \u003ch3 align=\"center\"\u003eA simple handler to standardize and handle HTTP request errors and responses in API's.\u003c/h3\u003e\n\n## Installation\n\n```sh\n  # Using NPM\n  npm i http-handler-response\n\n  # Using YARN\n  yarn add http-handler-response\n```\n\n## Using\n\nThe http-handler-response provides three main functions. `createException`, `createResponse` and `handlerError`.\n\n### createException\n\nThe `createException` function is the function responsible for formulating your return messages in unsuccessful requests. It follows the [RFC-7807](https://tools.ietf.org/html/rfc7807) standard.\n\n#### Parameters\n\n```js\n  // Object with response specifications\n  payload: {\n    code: number | string,    // HTTP status code 4xx to 5xx\n    type?: string,            // URL for a document describing the error condition\n    title?: string,           // Short and descriptive information\n    detail: string,           // Legible error description\n    instance?: string,        // URI exclusive for or specific error\n  }\n```\n\n#### Example\n\n```js\nimport { createException, handlerError } from 'http-handler-response'\nimport User from 'models/User'\n\nclass UserController {\n  async index(request, response) {\n    try {\n      const user = await User.find(1)\n\n      if (!user)\n        createException({\n          code: 404, // 404 or '404 - Not Found'\n          detail: 'The user informed is not registered.',\n          instance: '/users/1',\n          type: 'https://example.com/docs/users',\n        })\n\n      return user\n    } catch (error) {\n      handlerError(response, error)\n    }\n  }\n}\n```\n\n#### Response\n\n```js\n{\n  status: 404,\n  title: 'Not found',\n  detail: 'The user informed is not registered.',\n  instance: '/users/1',\n  type: 'https://example.com/docs/users',\n}\n\n```\n\n### createResponse\n\nThe `createResponse` function is the function responsible for formulating your return messages in successful requisitions.\n\n#### Parameters\n\n```js\n  // HTTP Response Object\n  response: object\n\n  // Object with response specifications\n  payload: {\n    code: number | string,    // HTTP status code 1xx to 3xx\n    title?: string,           // Short and descriptive information\n    message?: string,         // Legible action response\n    instance: string,         // URI exclusive for or specific error\n    data: object              // Back Data\n  }\n```\n\n#### Example\n\n```js\nimport { createResponse, handlerError } from 'http-handler-response'\nimport User from 'models/User'\n\nclass UserController {\n  async store(request, response) {\n    try {\n      const data = request.only(['name', 'email'])\n\n      const user = new User()\n      user.name = data.name\n      user.email = data.email\n      await user.save()\n\n      return createResponse(response, {\n        code: 201, // 201 or '201 - Created'\n        message: 'Successful registered user.',\n        data: user,\n      }),\n    } catch (error) {\n      handlerError(response, error)\n    }\n  }\n}\n```\n\n#### Response\n\n```js\n{\n  status: 201,\n  title: 'Created'\n  message: 'Successful registered user.'\n  data: {\n    id: 1,\n    name: 'User',\n    email: 'user@email.com'\n  }\n}\n```\n\n### handlerError\n\nhttp-handler-response has custom handlers for handling errors for various web frameworks, such as `AdonisJs`,` Express` and `KoaJs`. You can use it within your `catch` block on each call or create custom middleware responsible for handling exceptions globally in the HTTP context.\n\n#### Example\n\n```js\nimport { handlerError } from 'http-handler-response'\nimport User from 'models/User'\n\nclass UserController {\n  async store(request, response) {\n    try {\n      // Your code..\n    } catch (error) {\n      handlerError(response, error)\n    }\n  }\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaby%2Fhttp-handler-response","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fklaby%2Fhttp-handler-response","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fklaby%2Fhttp-handler-response/lists"}