{"id":13847039,"url":"https://github.com/PDMLab/http-problem","last_synced_at":"2025-07-12T08:31:14.421Z","repository":{"id":44103202,"uuid":"103652439","full_name":"PDMLab/http-problem","owner":"PDMLab","description":"Create problem+json documents with Node.js","archived":false,"fork":false,"pushed_at":"2023-07-11T00:58:17.000Z","size":306,"stargazers_count":22,"open_issues_count":3,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-06-18T19:52:28.758Z","etag":null,"topics":["http","hypermedia","nodejs","rest"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/httpproblem","language":"JavaScript","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/PDMLab.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}},"created_at":"2017-09-15T12:03:32.000Z","updated_at":"2025-03-22T13:15:50.000Z","dependencies_parsed_at":"2024-01-15T20:47:31.981Z","dependency_job_id":"fd878cc1-0214-4838-845c-27f8d6b03758","html_url":"https://github.com/PDMLab/http-problem","commit_stats":null,"previous_names":["pdmlab/httpproblem","pdmlab/problem-json"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/PDMLab/http-problem","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PDMLab%2Fhttp-problem","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PDMLab%2Fhttp-problem/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PDMLab%2Fhttp-problem/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PDMLab%2Fhttp-problem/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/PDMLab","download_url":"https://codeload.github.com/PDMLab/http-problem/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/PDMLab%2Fhttp-problem/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264962113,"owners_count":23689740,"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","hypermedia","nodejs","rest"],"created_at":"2024-08-04T18:00:52.955Z","updated_at":"2025-07-12T08:31:14.165Z","avatar_url":"https://github.com/PDMLab.png","language":"JavaScript","readme":"`http-problem` was the first approach to implement RFC7807. It is still there because it is used in several projects.[http-problem-details](https://github.com/PDMLab/http-problem-details) is a more recent implementation written in TypeScript with extensibility in mind. Most efforts will be put in this one but if somebody sends a PR for the old implementation it is likely it’ll be merged as well.\n\nSo if you’re not using a RFC7807 library right now, I would recommend [http-problem-details](https://github.com/PDMLab/http-problem-details) and its downstream libraries.\n\n# Create problem+json documents  with Node.js\n\n`httpproblem` is a small library that allos you to create `problem+json` documents according to [RFC 7807](https://tools.ietf.org/html/rfc7807).\n\n## Installation\n\n```\nnpm install --save httpproblem\n```\n\nor\n\n```\nyarn add httpproblem\n```\n\n## Usage\n\n`httpproblem` current supports these options:\n\n* `type` (string) - A URI reference [[RFC3986](https://tools.ietf.org/html/rfc3986)] that identifies the problem type.\n* `title` (string) - A short, human-readable summary of the problem type.\n* `status` (number) - The HTTP status code ([[RFC7231], Section 6](https://tools.ietf.org/html/rfc7231#section-6)) generated by the origin server for this occurrence of the problem. If only `status` is provided `type` will be set to `about:blank` and `title` will be become the reason phrase as of the HTTP spec, e.g. \"Not Found\" if `status` is `404`.\n* `instance` (stringt) - A URI reference that identifies the specific      occurrence of the problem.\n* Extension Members - Provide additional information.\n\n`type` and `instance` are validated to be valid URIs and will throw errors if not.\n\n### Example\n\nTo generate this `problem+json` result\n\n```json\n{\n    \"type\": \"https://example.com/probs/out-of-credit\",\n    \"title\": \"You do not have enough credit.\",\n    \"detail\": \"Your current balance is 30, but that costs 50.\",\n    \"instance\": \"/account/12345/msgs/abc\",\n    \"status\": 400\n}\n```\n\nthis code is required:\n\n```javascript\nconst httpProblem = require('httpproblem');\n\nconst doc = new httpProblem.Document({\n  type: 'https://example.com/probs/out-of-credit',\n  title: 'You do not have enough credit.',\n  detail: 'Your current balance is 30, but that costs 50.',\n  instance: '/account/12345/msgs/abc',\n  status: 400\n});\n```\n\n### Example with Extension Members\n\nTo generate this `problem+json` result\n\n```json\n{\n    \"type\": \"https://example.com/probs/out-of-credit\",\n    \"title\": \"You do not have enough credit.\",\n    \"balance\": 30,\n    \"accounts\": [\"/account/12345\", \"/account/67890\"]\n}\n```\n\nthis code is required:\n\n```javascript\nconst httpProblem = require('httpproblem');\n\nconst extension = new httpProblem.Extension({\n  balance: 30,\n  accounts: ['/account/12345', '/account/67890']\n});\n\nconst doc = new httpProblem.Document({\n  type: 'https://example.com/probs/out-of-credit',\n  title: 'You do not have enough credit.'\n}, extension);\n```\n\n### StatusCodeProblems\n\n`httpproblem` also provides some default problems for HTTP Status Codes you can just create without providing further details.\n\nThe supported `StatusCodeProblems` you can create, are:\n\n- BadRequestProblem\n- UnauthorizedProblem\n- ForbiddenProblem,\n- NotFoundProblem,\n- InternalServerErrorProblem\n\nInstances can be created like this:\n\n```js\nconst httpProblem = require('httpproblem');\nconst problem = new httpProblem.StatusCodeProblems.UnauthorizedProblem();\n```\n\n## Running the tests\n\n```\nnpm test\n```\n\n## Want to help?\n\nThis project is just getting off the ground and could use some help with cleaning things up and refactoring.\n\nIf you want to contribute - we'd love it! Just open an issue to work against so you get full credit for your fork. You can open the issue first so we can discuss and you can work your fork as we go along.\n\nIf you see a bug, please be so kind as to show how it's failing, and we'll do our best to get it fixed quickly.\n\nBefore sending a PR, please [create an issue](https://github.com/PDMLab/project-json/issues/new) to introduce your idea and have a reference for your PR.\n\nAlso please add tests and make sure to run `npm run lint`.\n\n## License\n\nMIT License\n\nCopyright (c) 2017 - 2019 PDMLab\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n","funding_links":[],"categories":["JavaScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPDMLab%2Fhttp-problem","html_url":"https://awesome.ecosyste.ms/projects/github.com%2FPDMLab%2Fhttp-problem","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2FPDMLab%2Fhttp-problem/lists"}