{"id":28511224,"url":"https://github.com/harshdev1809/http-reply","last_synced_at":"2026-03-06T15:01:56.529Z","repository":{"id":295762992,"uuid":"991177323","full_name":"HarshDev1809/http-reply","owner":"HarshDev1809","description":"A lightweight Node.js utility for sending consistent, standardized HTTP responses across your API endpoints","archived":false,"fork":false,"pushed_at":"2025-06-13T17:42:08.000Z","size":58,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-21T18:04:55.710Z","etag":null,"topics":["api","api-rest","http","http-requests","https","javascript","rest-api"],"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/HarshDev1809.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,"zenodo":null}},"created_at":"2025-05-27T08:36:13.000Z","updated_at":"2025-06-13T17:42:11.000Z","dependencies_parsed_at":"2025-05-29T16:17:41.934Z","dependency_job_id":null,"html_url":"https://github.com/HarshDev1809/http-reply","commit_stats":null,"previous_names":["harshdev1809/http-reply"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/HarshDev1809/http-reply","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarshDev1809%2Fhttp-reply","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarshDev1809%2Fhttp-reply/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarshDev1809%2Fhttp-reply/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarshDev1809%2Fhttp-reply/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/HarshDev1809","download_url":"https://codeload.github.com/HarshDev1809/http-reply/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/HarshDev1809%2Fhttp-reply/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30182686,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-06T14:42:24.748Z","status":"ssl_error","status_checked_at":"2026-03-06T14:42:14.925Z","response_time":250,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"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":["api","api-rest","http","http-requests","https","javascript","rest-api"],"created_at":"2025-06-08T23:38:15.979Z","updated_at":"2026-03-06T15:01:56.513Z","avatar_url":"https://github.com/HarshDev1809.png","language":"TypeScript","readme":"# HttpReply\n\nA lightweight, flexible Node.js utility for standardizing HTTP responses in Express, Fastify, or custom server frameworks. `HttpReply` provides a consistent, customizable way to format and send HTTP responses, with support for timestamps, error logging, and custom adapters. Available as both ES6 modules and CommonJS, with no need for `.default` in ES module imports.\n\n## Features\n\n- **Framework Agnostic**: Compatible with Express, Fastify, or custom frameworks via adapters.\n- **Standardized Responses**: Ensures consistent response structure across your API.\n- **Configurable Options**: Customize response fields, timestamps, logging, and more.\n- **Static Methods**: Send responses without instantiating the class.\n- **Error Handling**: Built-in validation and logging for invalid configurations or response objects.\n- **TypeScript Support**: Fully typed with included TypeScript declarations.\n- **ES6 and CommonJS Support**: Use with `import` or `require`, no `.default` required for ES modules.\n\n## Installation\n\nInstall the package via npm:\n\n```bash\nnpm install http-reply\n```\n\n## Usage\n\n### Importing the Package\n\nThe package supports both ES6 modules and CommonJS:\n\n```javascript\n// ES6 Module\nimport { HttpReply } from 'http-reply';\n\n// CommonJS\nconst { HttpReply } = require('http-reply');\n```\n\n### Basic Example (Express)\n\nUse `HttpReply` to send standardized responses in your Express or Fastify application.\n\n```javascript\nimport { HttpReply } from 'http-reply';\nimport express from 'express';\n\nconst app = express();\n\napp.get('/example', (req, res) =\u003e {\n  HttpReply.success(res, {\n    message: 'Operation successful',\n    data: { user: 'John Doe' },\n    metaData: { requestId: '12345' },\n  });\n});\n\napp.listen(3000, () =\u003e console.log('Server running on port 3000'));\n```\n\n### Centralized Configuration\n\nCreate a centralized `HttpReply` instance for consistent configuration across your application.\n\nCreate a file (e.g., `responder.js`):\n\n```javascript\nimport { HttpReply } from 'http-reply';\n\nconst reply = new HttpReply({\n  includeTimestamp: true,\n  dateFormat: 'iso',\n  enableLogging: true,\n  customFields: { apiVersion: '1.0.0' },\n});\n\nexport default reply;\n```\n\nUse it in your routes:\n\n```javascript\nimport reply from './responder';\nimport express from 'express';\n\nconst app = express();\n\napp.get('/example', (req, res) =\u003e {\n  reply.success(res, {\n    message: 'Custom response',\n    data: { id: 1 },\n  });\n});\n\napp.listen(3000, () =\u003e console.log('Server running on port 3000'));\n```\n\n### Static Methods\n\nUse static methods for quick responses without instantiation:\n\n```javascript\nimport { HttpReply } from 'http-reply';\n\nHttpReply.created(res, {\n  message: 'User created',\n  data: { id: 123, name: 'Jane Doe' },\n});\n\nHttpReply.notFound(res, {\n  message: 'Resource not found',\n  error: 'Invalid ID',\n});\n```\n\n### Supported Response Methods\n\n`HttpReply` provides methods for common HTTP status codes:\n\n| Method               | Status Code | Description                              |\n|----------------------|-------------|------------------------------------------|\n| `success`            | 200         | Successful request                       |\n| `created`            | 201         | Resource created successfully            |\n| `accepted`           | 202         | Request accepted for processing          |\n| `noContent`          | 204         | No content to return                     |\n| `badRequest`         | 400         | Invalid request                          |\n| `unauthorized`       | 401         | Authentication required                  |\n| `forbidden`          | 403         | Access denied                            |\n| `notFound`           | 404         | Resource not found                       |\n| `conflict`           | 409         | Resource conflict                        |\n| `tooManyRequests`    | 429         | Rate limit exceeded                      |\n| `error`              | 500         | Internal server error                    |\n| `notImplemented`     | 501         | Feature not implemented                  |\n| `serviceUnavailable` | 503         | Service temporarily unavailable          |\n| `response`           | Custom      | Generic response with custom status code |\n\n### Configuration Options\n\nCustomize `HttpReply` with the following options when creating an instance:\n\n| Option             | Type     | Default  | Description                                                              |\n|--------------------|----------|----------|--------------------------------------------------------------------------|\n| `includeTimestamp` | Boolean  | `false`  | Include a timestamp in the response (`iso` or `unix` format).            |\n| `includeCode`      | Boolean  | `true`   | Include the status code in the response body.                            |\n| `includeMessage`   | Boolean  | `true`   | Include the message in the response body.                                |\n| `includeError`     | Boolean  | `true`   | Include error details in the response body.                              |\n| `includeMetaData`  | Boolean  | `true`   | Include metadata in the response body.                                   |\n| `enableLogging`    | Boolean  | `true`   | Enable error logging for invalid configurations or response objects.     |\n| `stringify`        | Boolean  | `false`  | Stringify the response body before sending (useful for custom adapters). |\n| `customFields`     | Object   | `{}`     | Additional fields to include in every response.                          |\n| `dateFormat`       | String   | `'unix'` | Format for timestamps (`'iso'` or `'unix'`).                             |\n| `adapter`          | Function | `null`   | Custom adapter for non-Express/Fastify frameworks.                       |\n\n### Custom Adapter Example\n\nFor non-Express/Fastify frameworks, provide a custom adapter:\n\n```javascript\nimport { HttpReply } from 'http-reply';\n\nconst reply = new HttpReply({\n  adapter: (res, statusCode, payload) =\u003e {\n    res.setStatusCode(statusCode);\n    res.setBody(payload);\n    return res;\n  },\n});\n\nreply.success(res, {\n  message: 'Custom adapter response',\n  data: { key: 'value' },\n});\n```\n\n### Example Response Output\n\nUsing the `success` method with default configuration:\n\n```javascript\nHttpReply.success(res, {\n  message: 'User fetched',\n  data: { id: 1, name: 'John' },\n  metaData: { total: 1 },\n});\n```\n\nOutput:\n\n```json\n{\n  \"message\": \"User fetched\",\n  \"data\": { \"id\": 1, \"name\": \"John\" },\n  \"metaData\": { \"total\": 1 },\n  \"code\": 200\n}\n```\n\nWith `includeTimestamp: true` and `dateFormat: 'iso'`:\n\n```json\n{\n  \"message\": \"User fetched\",\n  \"data\": { \"id\": 1, \"name\": \"John\" },\n  \"metaData\": { \"total\": 1 },\n  \"code\": 200,\n  \"timestamp\": \"2025-06-13T17:25:00.000Z\"\n}\n```\n\n## Dependencies\n\n- Node.js \u003e= 12.x\n- Express or Fastify (optional, depending on your framework)\n\n## Contributing\n\nWe welcome contributions! To contribute:\n\n1. Fork the repository.\n2. Create a new branch (`git checkout -b feature/your-feature`).\n3. Commit your changes (`git commit -m 'Add your feature'`).\n4. Push to the branch (`git push origin feature/your-feature`).\n5. Open a Pull Request.\n\nPlease ensure your code follows the project's coding standards and includes tests where applicable.\n\n## License\n\nThis project is licensed under the MIT License. See the [LICENSE](LICENSE) file for details.\n\n## Contact\n\nFor questions or support, open an issue on the [GitHub repository](https://github.com/HarshDev1809/http-reply/issues) or contact the maintainer at [dev182000@gmail.com](mailto:dev182000@gmail.com).\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharshdev1809%2Fhttp-reply","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fharshdev1809%2Fhttp-reply","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fharshdev1809%2Fhttp-reply/lists"}