{"_id":"@alpinesoft/express-plus","_rev":"1-a082085d7bbe01811c5a20acca426367","name":"@alpinesoft/express-plus","dist-tags":{"latest":"1.0.0"},"versions":{"1.0.0":{"name":"@alpinesoft/express-plus","version":"1.0.0","description":"Lightweight Express.js middleware aimed to create standardised REST APIs","main":"index.js","repository":{"type":"git","url":"https://github.com/bene/express-plus"},"author":{"name":"Benedict Allerberger"},"license":"MIT","private":false,"dependencies":{"@cesium133/forgjs":"^1.1.8"},"devDependencies":{"express":"^4.16.4"},"_id":"@alpinesoft/express-plus@1.0.0","dist":{"shasum":"9d615e4769e5069cca05ecdb54043864e019035f","integrity":"sha512-4QcUM+s7fMpWelbjUFUqV2/y/xl5TBi1FTFGm01zpgxp3eoWGubLWDkdvBGWtuo2DbWLnHYGn/Dmn+nJrlvN5g==","tarball":"https://registry.npmjs.org/@alpinesoft/express-plus/-/express-plus-1.0.0.tgz","fileCount":11,"unpackedSize":7600,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcNnUGCRA9TVsSAnZWagAAc+cQAKKgcDQqe6yCL/Ci4TKR\ngX6lM9OOW6AixKuyZQH4wsv1ZGiW6yOn4WFplWPDfVyXdbjhCvH1ORZCmnYY\n4ugyKsC7thH92N7VBjN2fDNcYcXupnsMLKT5d4ybQdd58j3gJlTPOlgnBhbs\nqra/tNDCCFpgVKAWR4g6KiLT6oOxk3dmJk0ucfueGaqTilWk4T8XSSsTQrRS\nt05LvzScZDFwtKuIBXnHgydp7U6+awNdTeUd8ONCccer729h7F1qbG/pn9HX\ncBFh4m8z1zukyvDA+4WVfvnYM5+EMWiiIaHLCEjrdrlEnD1A751qYxtg3/ER\nChu8dOnawjZHGFOcMg+YcUBLpHX3f0rJzYaGUTQ/OxbYQtgnirkOktPx+bKE\nMESEJ7iwBHrdp50rGhMzmjuqitrkwlkDqsWnH6wPpXyLdbVeBPLVAYQIb8xh\nKnSoT+eOkTzY/9JWHkXk2rFOjC84fOPcsvYjsk00am+Oc6yHlgL0qRWgWINF\nqVHhgYxXhD6/G1Zi1qGJWlB0gqYY5f8y3ZFs1FjcGGfb4dYMBMTQ4tKcXnbl\nAiPDZca4VajPo7zjt/XM5ChNMnTEOYCsObWPiRayEJwL4n0r493Ov7HKg0Am\nU/ZEWxXt+87R6/RTXdwflmkawKVPzoH86pCcpRR6MB6DWWp9JiXWcsrrm4q2\n2/hx\r\n=n1HG\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIHIOS7K3kOeg9GJMnez/Bj0eH9RV7XTsKRoYuGCartoJAiBcV2xQDntuJUGQBn11qL0bOLl3Zzw7tavvBi7Fy0fZIA=="}]},"maintainers":[{"name":"alpinesoft","email":"os@alpinesoft.eu"}],"_npmUser":{"name":"alpinesoft","email":"os@alpinesoft.eu"},"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/express-plus_1.0.0_1547072773908_0.6920109583121712"},"_hasShrinkwrap":false}},"time":{"created":"2019-01-09T22:26:13.734Z","1.0.0":"2019-01-09T22:26:14.080Z","modified":"2022-04-04T13:38:44.873Z"},"maintainers":[{"name":"alpinesoft","email":"os@alpinesoft.eu"}],"description":"Lightweight Express.js middleware aimed to create standardised REST APIs","repository":{"type":"git","url":"https://github.com/bene/express-plus"},"author":{"name":"Benedict Allerberger"},"license":"MIT","readme":"# ExpressPlus\n\nThis lightweight Express.js middleware focuses on two main features: \n\n* (Type-) checking the request body\n* Standardising the result/error format\n\n## Getting started\n```javascript\nconst expressPlus = require('express-plus')\napp.use(expressPlus.createMiddleware())\n```\n\n## Check request body\n```javascript\nconst { Rule } = require('@cesium133/forgjs')\nconst bodyRules = {\n    username: new Rule({\n      type: 'string',\n      minLength: 3,\n      maxLength: 120,\n      notEmpty: true\n  }),\n  password: new Rule({\n      type: 'password',\n      minLength: 3,\n      maxLength: 120,\n      notEmpty: true\n  })\n}\n\napp.post('/', (req, res) => {\n    \n    const isValid = req.checkBody(bodyRules)\n    \n    // Error will be sent automatically\n    if (!isValid) {\n        return\n    }\n    \n    // Continue handling the request if body is valid\n})\n```\nThis will result in:\n```JSON\n{\n    \"status\": \"ERROR\",\n    \"error\": {\n        \"name\": \"Invalid request body\",\n        \"message\": \"Could not parse request body, check for invalid or missing fields\"\n    }\n}\n```\n\n## Return data if request is successful\n```javascript\napp.post('/', (req, res) => {\n    res.resolve({\n        yourData: 'FOR-EXAMPLE-A-TOKEN'\n    })\n})\n```\n\nThis will result in:\n```JSON\n{\n    \"status\": \"SUCCESS\",\n    \"payload\": {\n        \"yourData\": \"FOR-EXAMPLE-A-TOKEN\"\n    }\n}\n```\n\n## Create custom errors\n```javascript\nres.reject(expressPlus.createHttpError(500, 'Your error', 'Provide a concise error message.'))\n```\nor\n```javascript\nnext(expressPlus.createHttpError(500, 'Your error', 'Provide a concise error message.'))\n```\n\n## Handle errors\n```javascript\napp.use(expressPlus.createErrorHandler())\n```\nPlace this middleware usage call **after** every other to ensure full error handling. To learn more about Express.js error handling follow [this](https://expressjs.com/en/guide/error-handling.html) link.\n\nYou can see a full example [here](https://github.com/bene/express-plus/tree/master/example).","readmeFilename":"README.md"}