{"id":19558782,"url":"https://github.com/thejfreitas/ts-http-status-utils","last_synced_at":"2025-08-08T23:13:26.623Z","repository":{"id":41442403,"uuid":"460236776","full_name":"thejfreitas/ts-http-status-utils","owner":"thejfreitas","description":"HTTP status code declarations, descriptions and utils.","archived":false,"fork":false,"pushed_at":"2024-01-22T14:35:49.000Z","size":1437,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-04-23T19:39:08.229Z","etag":null,"topics":["http","status-code","status-code-constants","status-codes","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/ts-http-status-utils","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/thejfreitas.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-17T01:20:34.000Z","updated_at":"2022-06-25T18:42:32.000Z","dependencies_parsed_at":"2024-01-22T16:45:06.338Z","dependency_job_id":null,"html_url":"https://github.com/thejfreitas/ts-http-status-utils","commit_stats":{"total_commits":80,"total_committers":1,"mean_commits":80.0,"dds":0.0,"last_synced_commit":"908ba55c1763a21f59ed9f8f545be9fb69f4e361"},"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejfreitas%2Fts-http-status-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejfreitas%2Fts-http-status-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejfreitas%2Fts-http-status-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/thejfreitas%2Fts-http-status-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/thejfreitas","download_url":"https://codeload.github.com/thejfreitas/ts-http-status-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240815274,"owners_count":19862033,"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":["http","status-code","status-code-constants","status-codes","typescript"],"created_at":"2024-11-11T04:48:09.547Z","updated_at":"2025-02-26T08:19:35.520Z","avatar_url":"https://github.com/thejfreitas.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# ts-http-status-utils :hammer_and_wrench: :computer: :toolbox:\n\nHTTP status code declarations, status phrases, descriptions and util functions\n\n## Motivation\n\nWorking on different projects dealing with microservices or different responses\nfrom distributed APIs I noticed that some developers used to default failed\nresponses to Http code `500 - Internal Server Error` instead of an appropriate\nHttp code making the debug process harder and misleading depending how you\nimplement logging tools.\n\nTaking advantage of `TypeScript` and `Docstrings`, this library helps developers\nto handle and understand HTTP responses easily as well making it easy to build,\nintegrate or debug microservices or APIs.\n\n### [How to use](#how-to-use-in-a-real-project)\n\n---\n\n### Available enums\n\n`RequestMethod, StatusCode, StatusPhrase, StatusDescription, StatusLabel`\n\n### RequestMethod\n\n```javascript\nRequestMethod.GET;\n\n// Return \"GET\"\n\nRequestMethod.POST;\n\n// Return \"POST\"\n```\n\n### StatusCode\n\n```javascript\nStatusCode.CONTINUE;\n\n// Return 100\n\nStatusCode.OK;\n\n// Return 200\n```\n\n### StatusPhrase\n\n```javascript\nStatusPhrase.PROCESSING;\n\n// Return \"Processing\"\n\nStatusPhrase.MOVED_PERMANENTLY;\n\n// Return \"Moved Permanently\"\n```\n\n### StatusDescription\n\n```javascript\nStatusDescription.CREATED;\n\n// Return \"The request succeeded, and a new resource was created as a result. This is typically the response sent after POST requests, or some PUT requests.\"\n```\n\n### StatusLabel\n\n```javascript\nStatusLabel.CREATED;\n\n// Return \"CREATED\"\n\nStatusLabel.ALREADY_REPORTED;\n\n// Return \"ALREADY_REPORTED\"\n```\n\n### Available functions\n\n`getStatusPhraseByCode, getStatusDescriptionByCode, makeHttpResponsesDictionary`\n\n### getStatusPhraseByCode\n\n```javascript\ngetStatusPhraseByCode(StatusCode.PROXY_AUTHENTICATION_REQUIRED);\n\n// Return \"Proxy Authentication Required\"\n```\n\n### getStatusDescriptionByCode\n\n```javascript\ngetStatusDescriptionByCode(StatusCode.BAD_GATEWAY);\n\n// Return \"This error response means that the server, while working as a gateway to get a response needed to handle the request, got an invalid response.\"\n```\n\n### makeHttpResponsesDictionary\n\nCreate a dictionary containing all HTTP responses\n\n```javascript\n{\n'100': {\n    code: 100,\n    phrase: 'Continue',\n    description: 'This interim response indicates that the client should continue the request or ignore the response if the request is already finished.'\n},\n'101': {\n    code: 101,\n    phrase: 'Switching Protocols',\n    description: 'This code is sent in response to an Upgrade request header from the client and indicates the protocol the server is switching to.'\n},\n    ...\n\n'511': {\n    code: 511,\n    phrase: 'Network Authentication Required',\n    description: 'Indicates that the client needs to authenticate to gain network access.'\n}\n```\n\n```javascript\n\nconst dictionary = makeHttpResponsesDictionary();\n\ndictionary[StatusCode.OK];\n\n/**\nreturn\n    '200': {\n        code: 200,\n        phrase: 'OK',\n        description: 'The request succeeded. The result meaning of `success` depends on the HTTP method.'\n    }\n* /\n\n```\n\n## How to use in a real project\n\n```javascript\nimport {\n  StatusCode,\n  getStatusPhraseByCode,\n  RequestMethod,\n  getStatusDescriptionByCode,\n} from \"ts-http-status-utils\";\n\nexport const lambdaHandler = async (\n  event: APIGatewayProxyEvent,\n  context: Context\n): Promise\u003cAPIGatewayProxyResult\u003e =\u003e {\n  try {\n    // RequestMethod enum\n    if (event.httpMethod !== RequestMethod.GET) {\n      // getStatusPhraseByCode and getStatusDescriptionByCode util functions \u0026 StatusCode.METHOD_NOT_ALLOWED\n      logError({\n        method: event.httpMethod,\n        statusCode: StatusCode.METHOD_NOT_ALLOWED,\n        statusPhrase: getStatusPhraseByCode(StatusCode.METHOD_NOT_ALLOWED),\n        statusDescription: getStatusDescriptionByCode(\n          StatusCode.METHOD_NOT_ALLOWED\n        ),\n      });\n\n      return {\n        // StatusCode enum\n        statusCode: StatusCode.METHOD_NOT_ALLOWED,\n        headers: {},\n        body: JSON.stringify({\n          // getStatusPhraseByCode util function\n          message: getStatusPhraseByCode(StatusCode.METHOD_NOT_ALLOWED),\n        }),\n      };\n    }\n\n    return {\n      // StatusCode enum\n      statusCode: StatusCode.OK,\n      // getStatusPhraseByCode util function\n      body: JSON.stringify({\n        message: `${getStatusPhraseByCode(\n          StatusCode.OK\n        )} - Response from lambda`,\n      }),\n    };\n  } catch (error) {\n    // getStatusPhraseByCode and getStatusDescriptionByCode util functions\n    logError({\n      method: event.httpMethod,\n      statusCode: error.statusCode,\n      statusPhrase: getStatusPhraseByCode(error.statusCode),\n      statusDescription: getStatusDescriptionByCode(error.statusCode),\n    });\n\n    return {\n      statusCode: error.statusCode,\n      body: JSON.stringify({\n        message:\n          error instanceof Error ? error.stack : JSON.stringify(error, null, 2),\n      }),\n    };\n  }\n};\n```\n\n## Resources\n\n[https://developer.mozilla.org/en-US/docs/Web/HTTP/Status](https://developer.mozilla.org/en-US/docs/Web/HTTP/Status)\n\n[https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods)\n\n[https://datatracker.ietf.org/doc/html/rfc7231](https://datatracker.ietf.org/doc/html/rfc7231)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejfreitas%2Fts-http-status-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fthejfreitas%2Fts-http-status-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fthejfreitas%2Fts-http-status-utils/lists"}