{"_id":"@anot/http-response-builder","_rev":"5-655b531deadd55106a4cf4fce0a3244a","name":"@anot/http-response-builder","dist-tags":{"latest":"0.1.4"},"versions":{"0.1.0":{"name":"@anot/http-response-builder","version":"0.1.0","keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"author":{"name":"kyanh"},"license":"ISC","_id":"@anot/http-response-builder@0.1.0","maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"dist":{"shasum":"2fea3e311069ca8b9884a325f2208aa0ab13a469","tarball":"https://registry.npmjs.org/@anot/http-response-builder/-/http-response-builder-0.1.0.tgz","fileCount":13,"integrity":"sha512-JqOT0nEcue0A+fFBr50GHpiPYanHPzpk86CxwaqMPtfRjryPUz2DOR5TX5/545Risx/4Kgjjq8ujcCT0S5agrQ==","signatures":[{"sig":"MEUCIAOmS+RY7QqbCxWCKDKPT7rvY+JjPt+C4RHqDpMMdxZEAiEA9xT/HZuq5bFExao+TiiMVoBzN8s6J5dcqSTxhChv8No=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":54155},"main":"dist/es5/index.cjs","type":"module","types":"dist/d.ts/index.d.ts","module":"dist/es6/index.js","exports":{".":{"types":"./dist/d.ts/index.d.ts","import":"./dist/es6/index.js","require":"./dist/es5/index.cjs"}},"gitHead":"5c43d52dd338cb571d4ecf61ca3eafa629e55f24","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"npm run build:es5 && npm run build:es6 && npm run build:ts && npm run rename-to-cjs","build:ts":"tsc --project tsconfig.d.ts.json","build:es5":"tsc --project tsconfig.es5.json","build:es6":"tsc --project tsconfig.es6.json","rename-to-cjs":"node -e \"const fs=require('fs');const path=require('path');const dir='./dist/es5';fs.readdirSync(dir).forEach(f=>{if(f.endsWith('.js')){fs.renameSync(path.join(dir,f),path.join(dir,f.replace('.js','.cjs')))}})\""},"_npmUser":{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"},"_npmVersion":"9.4.0","description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","directories":{},"_nodeVersion":"20.12.1","dependencies":{"dist":"^0.1.2","rename":"^1.0.4","http-status-response-anot":"^0.1.0-beta"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@typescript-eslint/parser":"^8.19.1","@typescript-eslint/eslint-plugin":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/http-response-builder_0.1.0_1737388562237_0.4629473007714524","host":"s3://npm-registry-packages-npm-production"}},"0.1.1":{"name":"@anot/http-response-builder","version":"0.1.1","keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"author":{"name":"kyanh"},"license":"ISC","_id":"@anot/http-response-builder@0.1.1","maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"dist":{"shasum":"c2c906059b4a3774caf8d111ba5e0f1a2980ec45","tarball":"https://registry.npmjs.org/@anot/http-response-builder/-/http-response-builder-0.1.1.tgz","fileCount":13,"integrity":"sha512-h3zkqY9x6G0Bf8GW1RWDk+Mv6ValUsEK3QEimazHAhngOQNqi9dq3pF7WNE5Vomsvydo4RKRdkOZaFaKqPV+Ng==","signatures":[{"sig":"MEUCIC0gdouRcMPuKzX1mevNPupqEs/d48TBl73cMcJXYzZDAiEAtJHavaKGdJWH81u56HttCrrtwaevgWWU+5hL3AJL0sk=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":53998},"main":"dist/es5/index.cjs","type":"module","types":"dist/d.ts/index.d.ts","module":"dist/es6/index.js","exports":{".":{"types":"./dist/d.ts/index.d.ts","import":"./dist/es6/index.js","require":"./dist/es5/index.cjs"}},"gitHead":"5c43d52dd338cb571d4ecf61ca3eafa629e55f24","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"npm run build:es5 && npm run build:es6 && npm run build:ts && npm run rename-to-cjs","build:ts":"tsc --project tsconfig.d.ts.json","build:es5":"tsc --project tsconfig.es5.json","build:es6":"tsc --project tsconfig.es6.json","rename-to-cjs":"node -e \"const fs=require('fs');const path=require('path');const dir='./dist/es5';fs.readdirSync(dir).forEach(f=>{if(f.endsWith('.js')){fs.renameSync(path.join(dir,f),path.join(dir,f.replace('.js','.cjs')))}})\""},"_npmUser":{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"},"_npmVersion":"9.4.0","description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","directories":{},"_nodeVersion":"20.12.1","dependencies":{"dist":"^0.1.2","rename":"^1.0.4","http-status-response-anot":"^0.1.0-beta"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@typescript-eslint/parser":"^8.19.1","@typescript-eslint/eslint-plugin":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/http-response-builder_0.1.1_1737389466117_0.11706679940853482","host":"s3://npm-registry-packages-npm-production"}},"0.1.2":{"name":"@anot/http-response-builder","version":"0.1.2","keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"author":{"name":"kyanh"},"license":"ISC","_id":"@anot/http-response-builder@0.1.2","maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"dist":{"shasum":"c61de8fc0a798147cf9a96de710a4883f79a3f50","tarball":"https://registry.npmjs.org/@anot/http-response-builder/-/http-response-builder-0.1.2.tgz","fileCount":13,"integrity":"sha512-nUCAcd4Ki7uKDllVB4ASti2EH4dl+oeekMhxa1ASE7QkoWS9s+nxr26aR0hSKYmbybA3oDAnK2IJarjBoJkc2w==","signatures":[{"sig":"MEUCIAe1oDARbAIZyTZ+qyk26H3vSauFYXmmNNjZtXIas8m/AiEAzUHKucGymm5/PJRcWtiL4OXimLkA9LBsuVw+2bTX8ic=","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":53914},"main":"dist/es5/index.cjs","type":"module","types":"dist/d.ts/index.d.ts","module":"dist/es6/index.js","exports":{".":{"types":"./dist/d.ts/index.d.ts","import":"./dist/es6/index.js","require":"./dist/es5/index.cjs"}},"gitHead":"5c43d52dd338cb571d4ecf61ca3eafa629e55f24","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"npm run build:es5 && npm run build:es6 && npm run build:ts && npm run rename-to-cjs","build:ts":"tsc --project tsconfig.d.ts.json","build:es5":"tsc --project tsconfig.es5.json","build:es6":"tsc --project tsconfig.es6.json","rename-to-cjs":"node -e \"const fs=require('fs');const path=require('path');const dir='./dist/es5';fs.readdirSync(dir).forEach(f=>{if(f.endsWith('.js')){fs.renameSync(path.join(dir,f),path.join(dir,f.replace('.js','.cjs')))}})\""},"_npmUser":{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"},"_npmVersion":"9.4.0","description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","directories":{},"_nodeVersion":"20.12.1","dependencies":{"dist":"^0.1.2","rename":"^1.0.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@typescript-eslint/parser":"^8.19.1","@typescript-eslint/eslint-plugin":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/http-response-builder_0.1.2_1737436768783_0.21297730468340403","host":"s3://npm-registry-packages-npm-production"}},"0.1.3":{"name":"@anot/http-response-builder","version":"0.1.3","keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"author":{"name":"kyanh"},"license":"ISC","_id":"@anot/http-response-builder@0.1.3","maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"dist":{"shasum":"e57ef76133b08fc71ba2815f534be72b3bce3f3a","tarball":"https://registry.npmjs.org/@anot/http-response-builder/-/http-response-builder-0.1.3.tgz","fileCount":22,"integrity":"sha512-NsjCCOcSid+QknI5K8JakALorvtQhRHUimujNfVjVD8b9q/H8/iwoUr/ujhnXw0zgkd4ElYDDeB91SM5SN9WKw==","signatures":[{"sig":"MEYCIQD9ruzjYaDvJoGual4j8V2gVes05Znz3dM9Q5tEeaa1iAIhAILe1OC+qjSan9NDqH7besKON8sMhvCGNYdmC5StwUXY","keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U"}],"unpackedSize":71561},"main":"dist/es5/index.cjs","type":"module","types":"dist/d.ts/index.d.ts","module":"dist/es6/index.js","exports":{".":{"types":"./dist/d.ts/index.d.ts","import":"./dist/es6/index.js","require":"./dist/es5/index.cjs"}},"gitHead":"7dae9cec7d9b131672c4821b5f69b0d920047e3b","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build":"npm run build:es5 && npm run build:es6 && npm run build:ts && npm run rename-to-cjs","build:ts":"tsc --project tsconfig.d.ts.json","build:es5":"tsc --project tsconfig.es5.json","build:es6":"tsc --project tsconfig.es6.json","rename-to-cjs":"node -e \"const fs=require('fs');const path=require('path');const dir='./dist/es5';fs.readdirSync(dir).forEach(f=>{if(f.endsWith('.js')){fs.renameSync(path.join(dir,f),path.join(dir,f.replace('.js','.cjs')))}})\""},"_npmUser":{"name":"botodale","actor":{"name":"botodale","type":"user","email":"nguyenkyanh.tanmai@gmail.com"},"email":"nguyenkyanh.tanmai@gmail.com"},"_npmVersion":"10.9.2","description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","directories":{},"_nodeVersion":"22.15.0","dependencies":{"dist":"^0.1.2","rename":"^1.0.4"},"publishConfig":{"access":"public"},"_hasShrinkwrap":false,"devDependencies":{"tsx":"^4.19.2","eslint":"^9.17.0","typescript":"^5.7.3","@types/node":"^22.10.5","@typescript-eslint/parser":"^8.19.1","@typescript-eslint/eslint-plugin":"^8.19.1"},"_npmOperationalInternal":{"tmp":"tmp/http-response-builder_0.1.3_1750780304939_0.7751383373555885","host":"s3://npm-registry-packages-npm-production"}},"0.1.4":{"name":"@anot/http-response-builder","version":"0.1.4","publishConfig":{"access":"public"},"description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","main":"dist/es5/index.cjs","module":"dist/es6/index.js","types":"dist/d.ts/index.d.ts","type":"module","scripts":{"test":"echo \"Error: no test specified\" && exit 1","build:es5":"tsc --project tsconfig.es5.json","build:es6":"tsc --project tsconfig.es6.json","build:ts":"tsc --project tsconfig.d.ts.json","build":"npm run build:es5 && npm run build:es6 && npm run build:ts && npm run rename-to-cjs","rename-to-cjs":"node -e \"const fs=require('fs');const path=require('path');const dir='./dist/es5';fs.readdirSync(dir).forEach(f=>{if(f.endsWith('.js')){fs.renameSync(path.join(dir,f),path.join(dir,f.replace('.js','.cjs')))}})\""},"exports":{".":{"require":"./dist/es5/index.cjs","import":"./dist/es6/index.js","types":"./dist/d.ts/index.d.ts"}},"keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"author":{"name":"kyanh"},"license":"ISC","devDependencies":{"@types/node":"^22.10.5","@typescript-eslint/eslint-plugin":"^8.19.1","@typescript-eslint/parser":"^8.19.1","eslint":"^9.17.0","tsx":"^4.19.2","typescript":"^5.7.3"},"dependencies":{"dist":"^0.1.2","rename":"^1.0.4"},"_id":"@anot/http-response-builder@0.1.4","gitHead":"7dae9cec7d9b131672c4821b5f69b0d920047e3b","_nodeVersion":"22.15.0","_npmVersion":"10.9.2","dist":{"integrity":"sha512-ctMSKpVg/i8VliBV1mSlolrU+ACTaY+n/LtMAx9kRbLEiGll7Jci/9kQxorMZ3LPbiD2oI9YdpnszgKRpGtxEQ==","shasum":"bb3fda045282ebbdb5e1061b3c6c8d7ac8300c15","tarball":"https://registry.npmjs.org/@anot/http-response-builder/-/http-response-builder-0.1.4.tgz","fileCount":22,"unpackedSize":71573,"signatures":[{"keyid":"SHA256:DhQ8wR5APBvFHLF/+Tc+AYvPOdTpcIDqOhxsBHRwC7U","sig":"MEQCIDLiAkDVtZWLYTWVQPkMgwfJLGXZBeE2irrW9ksMPdIRAiAKqml/GtWe7YbM75HN4KQI3QqNL7w3nnlfZTLi7ELLXA=="}]},"_npmUser":{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com","actor":{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com","type":"user"}},"directories":{},"maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/http-response-builder_0.1.4_1750780450765_0.225913342433945"},"_hasShrinkwrap":false}},"time":{"created":"2025-01-20T15:56:02.103Z","modified":"2025-06-24T15:54:11.162Z","0.1.0":"2025-01-20T15:56:02.453Z","0.1.1":"2025-01-20T16:11:06.348Z","0.1.2":"2025-01-21T05:19:28.989Z","0.1.3":"2025-06-24T15:51:45.111Z","0.1.4":"2025-06-24T15:54:10.986Z"},"author":{"name":"kyanh"},"license":"ISC","keywords":["http","response","javascript","typescript","nodejs","api","rest","http-status","response-builder"],"description":"A robust and type-safe library for constructing HTTP responses with optional paging and metadata. Designed for TypeScript and JavaScript, it ensures correct typing while simplifying the creation of various HTTP response types.","maintainers":[{"name":"botodale","email":"nguyenkyanh.tanmai@gmail.com"}],"readme":"# HTTP Response Builder\r\n\r\nA TypeScript package that provides a flexible and type-safe way to build HTTP responses with support for pagination, metadata, and standard HTTP status codes.\r\n\r\n## Features\r\n\r\n- Builder pattern for constructing HTTP responses\r\n- Type-safe response data handling with generics\r\n- Built-in pagination support\r\n- Metadata support for additional response information\r\n- Comprehensive HTTP status codes and messages\r\n- Fluent interface for method chaining\r\n\r\n## Installation\r\n\r\n```bash\r\nnpm install @anot/http-response-builder\r\n# or\r\nyarn add @anot/http-response-builder\r\n```\r\n\r\n## Basic Usage\r\n\r\nThe package provides a builder pattern to construct HTTP responses. Here's a simple example:\r\n\r\n```typescript\r\nimport { HttpResponseBuilder } from '@anot/http-response-builder';\r\n\r\nconst response = HttpResponseBuilder.ok()\r\n    .setData({ message: 'Hello World' })\r\n```\r\n\r\n## Usage with NestJS\r\n\r\n### Controller Example\r\n\r\n```typescript\r\nimport { Controller, Get } from '@nestjs/common';\r\nimport { HttpResponseBuilder, Paging } from '@anot/http-response-builder';\r\n\r\ninterface UserDTO {\r\n  id: number;\r\n  name: string;\r\n  email: string;\r\n}\r\n\r\n@Controller('users')\r\nexport class UsersController {\r\n  @Get()\r\n  async getUsers(): HttpResponseBuilder<UserDTO[]> {\r\n    const users: UserDTO[] = [\r\n      { id: 1, name: 'John Doe', email: 'john@example.com' },\r\n      { id: 2, name: 'Jane Doe', email: 'jane@example.com' }\r\n    ];\r\n\r\n    const totalUsers = users.length;\r\n    const paging = new Paging(1, 10, totalUsers);\r\n\r\n    return HttpResponseBuilder.ok<UserDTO[]>()\r\n      .setData(users)\r\n      .setPaging(paging)\r\n      .setMetadata({ timestamp: new Date() })\r\n  }\r\n\r\n  @Get(':id')\r\n  async getUser(): HttpResponseBuilder<UserDTO> {\r\n    const user: UserDTO = { \r\n      id: 1, \r\n      name: 'John Doe', \r\n      email: 'john@example.com' \r\n    };\r\n\r\n    return HttpResponseBuilder.ok<UserDTO>()\r\n      .setData(user)\r\n  }\r\n}\r\n```\r\n\r\n## Usage with Express\r\n\r\n### Route Handler Example\r\n\r\n```typescript\r\nimport express from \"express\";\r\nconst app = express();\r\nimport { HttpResponseBuilder, Paging } from \"@anot/http-response-builder\";\r\n\r\nvar server = app.listen(3000, function () {\r\n  console.log(\"Node.js is listening to PORT:\" + server.address().port);\r\n});\r\n\r\nvar photoList = [\r\n  {\r\n    id: \"001\",\r\n    name: \"photo001.jpg\",\r\n    type: \"jpg\",\r\n    dataUrl: \"http://localhost:3000/data/photo001.jpg\",\r\n  },\r\n  {\r\n    id: \"002\",\r\n    name: \"photo002.jpg\",\r\n    type: \"jpg\",\r\n    dataUrl: \"http://localhost:3000/data/photo002.jpg\",\r\n  },\r\n];\r\n\r\napp.get(\"/api/photo/list\", function (req, res, next) {\r\n  const results = HttpResponseBuilder.ok()\r\n          .setData(photoList)\r\n          .setMessage(\"Successfully fetched photo list\")\r\n          .setMetadata({ timestamp: new Date() })\r\n  res.json(results)\r\n});\r\n```\r\n\r\n## Pagination Support\r\n\r\nThe `Paging` class provides pagination functionality:\r\n\r\n```typescript\r\nconst paging = new Paging(1, 10, 100);  // page 1, 10 items per page, 100 total items\r\nconst response = HttpResponseBuilder.ok<UserDTO[]>()\r\n    .setData(users)\r\n    .setPaging(paging)\r\n```\r\n\r\n## Metadata Support\r\n\r\nYou can include additional metadata in your response:\r\n\r\n```typescript\r\nconst metadata = {\r\n    timestamp: new Date(),\r\n    version: '1.0.0'\r\n};\r\n\r\nconst response = HttpResponseBuilder.ok<UserDTO>()\r\n    .setData(user)\r\n    .setMetadata(metadata)\r\n```\r\n\r\n\r\n\r\n## Predefined Status Codes\r\n\r\nThe builder includes methods for common HTTP status codes:\r\n\r\n- `HttpResponseBuilder.ok()`\r\n- `HttpResponseBuilder.created()`\r\n- `HttpResponseBuilder.badRequest()`\r\n- `HttpResponseBuilder.unauthorized()`\r\n- `HttpResponseBuilder.forbidden()`\r\n- `HttpResponseBuilder.notFound()`\r\n- `HttpResponseBuilder.internalServerError()`\r\n  And many more...\r\n\r\n## Custom Response\r\n\r\nYou can create a custom response with any status code:\r\n\r\n```typescript\r\nconst response = HttpResponseBuilder.customResponse<UserDTO>()\r\n    .setStatus(418)  // I'm a teapot\r\n    .setMessage(\"Custom message\")\r\n    .setData(user)\r\n```\r\n\r\n## Response Type Structure\r\n\r\nThe response object has the following structure:\r\n\r\n```typescript\r\n\r\n{\r\n  status: number;      // HTTP status code\r\n  message: string;     // Status message\r\n  data ? : T;           // Response data (generic type)\r\n  paging ? : {          // Optional pagination info\r\n    page: number;\r\n    size: number;\r\n    total: number;\r\n  };\r\n  metadata ? : Record<string, any>;  // Optional additional metadata\r\n  currentUser ? : {      // Optional current user info \r\n      id: number | string;\r\n      extraData: Record<string, any>;\r\n  }\r\n}\r\n```\r\n\r\n## Error Handling\r\n\r\nThe builder includes validation and will throw TypeError for invalid inputs:\r\n\r\n- Invalid status codes (must be between 100 and 599)\r\n- Invalid message types (must be string)\r\n- Invalid paging instance\r\n- Invalid metadata type (must be object)\r\n\r\n## Contributing\r\n\r\nContributions are welcome! Please feel free to submit a Pull Request.\r\n\r\n## License\r\n\r\nThis project is licensed under the ISC License","readmeFilename":"README.md"}