{"id":24914123,"url":"https://github.com/dpaulos6/http-status-utils","last_synced_at":"2025-07-12T08:33:35.719Z","repository":{"id":249686643,"uuid":"832226979","full_name":"dpaulos6/http-status-utils","owner":"dpaulos6","description":"A simple utility library for HTTP status codes.","archived":false,"fork":false,"pushed_at":"2025-01-02T10:11:07.000Z","size":3478,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-06-24T04:50:43.406Z","etag":null,"topics":[],"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/dpaulos6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":"CODE_OF_CONDUCT.md","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,"zenodo":null}},"created_at":"2024-07-22T15:17:51.000Z","updated_at":"2025-01-02T10:11:10.000Z","dependencies_parsed_at":"2024-07-31T09:51:21.919Z","dependency_job_id":"104c32ac-dcb5-4e0e-9769-6400f07e4810","html_url":"https://github.com/dpaulos6/http-status-utils","commit_stats":null,"previous_names":["dpaulos6/http-status-utils"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/dpaulos6/http-status-utils","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpaulos6%2Fhttp-status-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpaulos6%2Fhttp-status-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpaulos6%2Fhttp-status-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpaulos6%2Fhttp-status-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/dpaulos6","download_url":"https://codeload.github.com/dpaulos6/http-status-utils/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/dpaulos6%2Fhttp-status-utils/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":264962716,"owners_count":23689871,"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":[],"created_at":"2025-02-02T06:16:33.561Z","updated_at":"2025-07-12T08:33:35.697Z","avatar_url":"https://github.com/dpaulos6.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# http-status-utils\n\nA simple utility library for HTTP status codes.\n\nAll functions receive an integer, check if it's a valid HTTP status code, and then return the respective value.  \nIf the received value is not an integer or not a valid HTTP status code, it will throw an exception, preventing your app from compiling. This way, you can easily see if the problem in an API response is related to the status code and why.\n\nCheck [Usage](#usage) for further details on how to use it.\n\n## Installation\n\n```sh\nnpm install http-status-utils\n```\n\n## Usage\n\n### Simple Example\n\n```ts\nimport { getDescription, isSuccess } from 'http-status-utils'\n\n// Example: Get description of HTTP status code 200\nconsole.log(getDescription(200)) // Output: OK\n\n// Example: Check if HTTP status code 200 is a success\nconsole.log(isSuccess(200)) // Output: true\n```\n\n### Advanced Example with `fetch()`\n\n```ts\nimport fetch from 'node-fetch'\nimport { handleHttp } from 'http-status-utils'\n\nasync function fetchData() {\n  try {\n    const response = await fetch('https://example.com/api/v1/')\n    const { status } = response\n\n    // Use handleHttp to get status code details\n    const { description, isSuccess, isError, isTeapot } = handleHttp(status)\n\n    if (isError) {\n      console.error(`Error: ${description}`)\n      return\n    }\n\n    if (isTeapot) {\n      console.log(`Received HTTP status code ${status}: ${description}`)\n      return\n    }\n\n    if (!isSuccess) {\n      console.log(`Received HTTP status code ${status}: ${description}`)\n      return\n    }\n\n    // Parse and use the JSON data\n    const data = await response.json()\n    console.log('Fetched Data:', data)\n\n    // Example of using the data.description\n    console.log(`Status Description: ${description}`)\n  } catch (error) {\n    console.error('Network Error:', error)\n  }\n}\n\n// Call the function to fetch data\nfetchData()\n```\n\n### Using `handleHttp`\n\n```ts\nconst result = handleHttp(200)\nconsole.log(result.description) // Output: OK\nconsole.log(result.isSuccess) // Output: true\nconsole.log(result.isError) // Output: false\nconsole.log(result.isTeapot) // Output: false\n```\n\n## API\n\n### `getDescription(code: number): string`\n\nReturns the description for the given HTTP status code.\n\n**Example:**\n\n```ts\nconsole.log(getDescription(200)) // Output: OK\nconsole.log(getDescription(404)) // Output: Not Found\n```\n\n### `isSuccess(code: number): boolean`\n\nReturns true if the status code indicates success (2xx).\n\n**Example:**\n\n```ts\nconsole.log(isSuccess(200)) // Output: true\nconsole.log(isSuccess(404)) // Output: false\n```\n\n### `isError(code: number): boolean`\n\nReturns true if the status code indicates an error (4xx or 5xx).\n\n**Example:**\n\n```ts\nconsole.log(isError(200)) // Output: false\nconsole.log(isError(404)) // Output: true\n```\n\n### `isTeapot(code: number): boolean`\n\nReturns true if the status code indicates teapot (418).\n\n**Example:**\n\n```ts\nconsole.log(isTeapot(418)) // Output: true\nconsole.log(isTeapot(200)) // Output: false\n```\n\n### `handleHttp(code: number): { description: string, isSuccess: boolean, isError: boolean, isTeapot: boolean }`\n\nReturns an object containing the respective details for the given HTTP status code.\n\n**Example:**\n\n```ts\nconst result = handleHttp(200)\nconsole.log(result.description) // Output: OK\nconsole.log(result.isSuccess) // Output: true\nconsole.log(result.isError) // Output: false\nconsole.log(result.isTeapot) // Output: false\n```\n\n## Testing\n\nThis section provides information on how to test the functionalities of the http-status-utils project. Follow the steps below to ensure that all components are working as expected:\n\n1. **Unit Tests**: Run the unit tests to verify the correctness of individual functions and methods.\n2. **Integration Tests**: Execute integration tests to ensure that different parts of the application work together seamlessly.\n3. **Manual Testing**: Perform manual testing to catch any issues that automated tests might miss.\n\nMake sure to review the test results and address any failures or errors. Keeping the tests up-to-date with the latest changes in the codebase is crucial for maintaining the reliability of the project.\n\nIf you want to test the library's functionality, you can do so by running:\n\n```sh\nnpm test\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpaulos6%2Fhttp-status-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdpaulos6%2Fhttp-status-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdpaulos6%2Fhttp-status-utils/lists"}