{"id":29287887,"url":"https://github.com/devrgd/server-response-helper","last_synced_at":"2026-03-16T16:32:22.629Z","repository":{"id":302252007,"uuid":"1011776341","full_name":"DevRGD/server-response-helper","owner":"DevRGD","description":"Elegant Express middleware for consistent JSON API responses with .response(), TypeScript support, and zero dependencies.","archived":false,"fork":false,"pushed_at":"2025-07-01T10:20:24.000Z","size":10,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-07-01T11:28:34.459Z","etag":null,"topics":["api","express","helper","http","json","middleware","nodejs","npm-package","response","rest","server","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/server-response-helper","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/DevRGD.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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-07-01T10:20:21.000Z","updated_at":"2025-07-01T10:24:08.000Z","dependencies_parsed_at":"2025-07-01T11:39:06.764Z","dependency_job_id":null,"html_url":"https://github.com/DevRGD/server-response-helper","commit_stats":null,"previous_names":["devrgd/server-response-helper"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/DevRGD/server-response-helper","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRGD%2Fserver-response-helper","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRGD%2Fserver-response-helper/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRGD%2Fserver-response-helper/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRGD%2Fserver-response-helper/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/DevRGD","download_url":"https://codeload.github.com/DevRGD/server-response-helper/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/DevRGD%2Fserver-response-helper/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":263837459,"owners_count":23517950,"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":["api","express","helper","http","json","middleware","nodejs","npm-package","response","rest","server","typescript"],"created_at":"2025-07-06T02:07:27.762Z","updated_at":"2026-03-16T16:32:22.616Z","avatar_url":"https://github.com/DevRGD.png","language":"TypeScript","readme":"# Server Response Helper\n\n\u003cp align=\"left\"\u003e\n  \u003cstrong\u003e\n    An elegant Express middleware that provides a \u003ccode\u003e.response()\u003c/code\u003e helper to create consistent, standardized JSON responses across your API. Features include custom messages, TypeScript support, and zero dependencies.\n  \u003c/strong\u003e\n\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n  \u003ca href=\"https://www.npmjs.com/package/server-response-helper\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/v/server-response-helper?style=for-the-badge\u0026logo=npm\u0026logoColor=white\u0026color=indigo\" alt=\"NPM Version\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://www.npmjs.com/package/server-response-helper\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/dm/server-response-helper?style=for-the-badge\u0026logo=npm\u0026logoColor=white\u0026color=teal\" alt=\"NPM Downloads\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/DevRGD/server-response-helper/actions/workflows/release.yml\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/actions/workflow/status/DevRGD/server-response-helper/release.yml?branch=main\u0026style=for-the-badge\u0026logo=github\u0026logoColor=white\u0026color=indigo\" alt=\"Build Status\"\u003e\n  \u003c/a\u003e\n  \u003ca href=\"LICENSE\" target=\"_blank\"\u003e\n    \u003cimg src=\"https://img.shields.io/npm/l/server-response-helper?style=for-the-badge\u0026logo=files\u0026logoColor=white\u0026color=teal\" alt=\"License\"\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n## 🤔 Why `server-response-helper`?\n\nIn modern API development, **consistency is key**. Clients consuming your API expect a predictable response structure. This tiny helper enforces a **standard JSON response format** across all your endpoints, making your API more robust and easier to work with.\n\n- ✅ **Standardize Responses**: Uniform structure (`status`, `message`, `data`, `timestamp`, `path`)\n- 🚀 **Lightweight \u0026 Fast**: Zero dependencies, minimal overhead\n- ✨ **Easy to Use**: Plug-and-play setup\n- 🔒 **Fully Typed**: Built in TypeScript for safety and autocompletion\n\n---\n\n## 🚀 Installation\n\n```bash\nnpm install server-response-helper\n```\n\n---\n\n## 💡 Usage\n\n### 1. Register the Middleware\n\nImport the default `response` middleware and register it with Express.\n\n```ts\nimport express from 'express';\nimport response from 'server-response-helper';\n\nconst app = express();\n\napp.use(response);\n```\n\n### 2. Send Standardized Responses\n\n**🏷️ Example A – custom message (string)**\n\n```ts\napp.post('/api/login', (req, res) =\u003e {\n  const user = { id: 1, name: 'Gautam' };\n  res.response(200, 'Login successful!', { user });\n});\n```\n\n**Result:**\n\n```json\n{\n  \"status\": 200,\n  \"message\": \"Login successful!\",\n  \"data\": { \"user\": { \"id\": 1, \"name\": \"Gautam\" } },\n  \"timestamp\": \"2025-07-01T01:02:45.000Z\",\n  \"path\": \"/api/login\"\n}\n```\n\n**🏷️ Example B – default message (number index)**\n\n```ts\napp.get('/api/item/:id', (req, res) =\u003e {\n  res.response(404);\n});\n```\n\n**Assuming:**\n\n```ts\nstatusMessages[404] = ['Not found', 'Nothing here'];\n```\n\n**Result:**\n\n```json\n{\n  \"status\": 404,\n  \"message\": \"Not found\",\n  \"timestamp\": \"2025-07-01T01:02:45.000Z\",\n  \"path\": \"/api/item/42\"\n}\n```\n\n---\n\n## 📚 API Reference\n\n### `responseHelper()`\n\nExpress middleware that extends `res` with `.response()`.\n\n### `res.response(status, [messageOrIndex], [data], [path])`\n\n| Parameter        | Type               | Default     | Description                                                                           |\n| ---------------- | ------------------ | ----------- | ------------------------------------------------------------------------------------- |\n| `status`         | `number`           | —           | **Required.** HTTP status code (`200`, `404`, etc.)                                   |\n| `messageOrIndex` | `string \\| number` | `0`         | Use a **string** for a custom message, or a **number** to index into default messages |\n| `data`           | `any`              | `undefined` | Optional payload under `data` field                                                   |\n| `path`           | `string`           | `req.path`  | Optional override of the `path` field                                                 |\n\n---\n\n## 🤝 Contributing\n\nWe welcome contributions! Here's how to get started:\n\n### 1. Clone\n\n```bash\ngit clone https://github.com/DevRGD/server-response-helper.git\ncd server-response-helper\n```\n\n### 2. Install dependencies\n\n```bash\nnpm ci\n```\n\n### 3. Run tests\n\n```bash\nnpm test\n```\n\n### 4. Lint and format before pushing\n\n```bash\nnpm run lint\nnpm run format\n```\n\n### 5. Build for publishing\n\n```bash\nnpm run build\n```\n\nThen push your feature branch and open a PR.\n\n---\n\n## 📜 License\n\nMIT © [DevRGD](https://github.com/DevRGD). See the [LICENSE](LICENSE) file.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrgd%2Fserver-response-helper","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdevrgd%2Fserver-response-helper","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdevrgd%2Fserver-response-helper/lists"}