{"_id":"@alfa-wells/alfa-rest-server","_rev":"3-950c0953061fedb88a6cffe188a5bba2","name":"@alfa-wells/alfa-rest-server","dist-tags":{"latest":"0.1.2"},"versions":{"0.1.0":{"name":"@alfa-wells/alfa-rest-server","version":"0.1.0","description":"Preconfigured server for REST APIs","main":"src/index.js","scripts":{"test":"mocha --recursive"},"repository":{"type":"git","url":"git+https://github.com/llobeto/alfa-rest-server.git"},"author":{"name":"leolobeto"},"license":"ISC","bugs":{"url":"https://github.com/llobeto/alfa-rest-server/issues"},"homepage":"https://github.com/llobeto/alfa-rest-server#readme","dependencies":{"body-parser":"^1.18.3","compression":"^1.7.3","express":"^4.16.4"},"gitHead":"bde48dad0b56443d70e9496513133a0c25ca1ae1","_id":"@alfa-wells/alfa-rest-server@0.1.0","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"leolobeto","email":"leolobeto@gmail.com"},"dist":{"integrity":"sha512-oO+tG6C1kZKhEmEAowBZ+tTLKNNjoHVtE3iP97+jDimGYwfh/+tK08oVj2DP8FvfQvYq1+8s9Nk3408zz8f5wg==","shasum":"ed2fe0e7442913823b4811f972575fa0eb3ad0e2","tarball":"https://registry.npmjs.org/@alfa-wells/alfa-rest-server/-/alfa-rest-server-0.1.0.tgz","fileCount":7,"unpackedSize":7344,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcPBV2CRA9TVsSAnZWagAAXA8P/R/cckY3orzqGr9Fa9Wf\nYT3fwX1dw2GUB501HSWiTOF1g3jCgtONnMnizRTEC3oWgnlw7Y4cX81KM63Y\n9/EBWGo+LlSL8u0eKbbWGadfwswLMZ5zeODVRc/t5HM+iFzm3E00F6sb1gF5\nKlBjNu9xbP5zsj7oBFJgXilw17dqgRHPLf+KnU6rDfjfueRLZ0sPi2V6zBAQ\nr2DUM+GLJ44mBdfdy22+eejCpwFaJDO7NslBGuiaATWKYeEuTLQKkDwBHn/i\nOUaLNP/HDqvvwk4tnITyGwhEmMmYSYYQQMElVSGH78seZ94Gr16pwNQYdVGj\nioenTj+xdW/P3N6CQpD/qwAAHe7to9xKGL3W3IPkvRyRc8V8NUiwkrq1MkLJ\n8iMXj2XeOozdji4VvKipEqKV5/u6/UDo8l9yQlwJ3EXrRSp/09RoyMVrGk9F\njNtVR+1hKCDtjX946cLla4YubI0QFUKD+nFXy4UXFVY9tWWRmsSmgX5PzgwT\ni/JRgr218Vi6t42341sRO9W4m85yJqux78q1rFA9dAc3z2Oxqwhxbsa37sSk\n5gnuolLBjKG1PQo7HZxWCTVbRhhgOgwGGF9h6N0SzP8vPSWXtuD/Db1Y/XNa\n4RZORWDBoqQlXbMBMHKYZuio6ljjoP5qdlmalwkIxO3Ydb1dscnO6hb44Pm2\nmZLE\r\n=F+14\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQCiDg2f6RDyeB770DXfoBeH1HMrrjt8H1mQ+Ne48aBBJQIgQLgvyI/I1K4HNLHGfDn7at8M0dWHGauklUZAGJz5EBo="}]},"maintainers":[{"name":"leolobeto","email":"leolobeto@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/alfa-rest-server_0.1.0_1547441525605_0.4539566783534954"},"_hasShrinkwrap":false},"0.1.1":{"name":"@alfa-wells/alfa-rest-server","version":"0.1.1","description":"Preconfigured server for REST APIs","main":"src/index.js","scripts":{"test":"mocha --recursive"},"repository":{"type":"git","url":"git+https://github.com/llobeto/alfa-rest-server.git"},"author":{"name":"leolobeto"},"license":"ISC","bugs":{"url":"https://github.com/llobeto/alfa-rest-server/issues"},"homepage":"https://github.com/llobeto/alfa-rest-server#readme","dependencies":{"body-parser":"^1.18.3","compression":"^1.7.3","express":"^4.16.4"},"gitHead":"bde48dad0b56443d70e9496513133a0c25ca1ae1","_id":"@alfa-wells/alfa-rest-server@0.1.1","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"leolobeto","email":"leolobeto@gmail.com"},"dist":{"integrity":"sha512-q3f5RgjDM+vt+GuSbrbQNqBiTgOp5xwR4Xo1vFNwpL7O6wJXF/WJJuCXLHbt2MPH5hjuenTCGy8DMTWyv6211A==","shasum":"1ca8bfdcb0b9863a579218dff9cc6426f1c575c7","tarball":"https://registry.npmjs.org/@alfa-wells/alfa-rest-server/-/alfa-rest-server-0.1.1.tgz","fileCount":7,"unpackedSize":7407,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcPCEPCRA9TVsSAnZWagAAe+MP/i7yMThOW+ib1PREMF46\nVqMyN234OIrNc58+cAKI/ptGQ6mdPBca/nRPTl7BuuJ7ySr4ALCNfjTtW2fR\nToJyaL15vMs6D4w5XAfFygUUZMcWAfketMP6lJWk7RAPyfpMyU3B3POF9IPW\nxc4Jwx0tJINcU8yBHGBZFpM/Nc/C+IYevaY4Wrz8M2h9fBXF15stYg42nUqW\nYT143mzkm9yIwNv8dw9JSPUi0TFX8xSAGDi2D1yJWOzJ1Ex2CEAYjEmlU3bq\nb9WJEmeg7vTY4dBYk5LhOcLaQxrYGax7NhBl3eU4mMCEQu5aIqjFKU/tpIjt\n9PWCWeqmNiw+ebkv09iwSqKm9YULLzd00uDeuoS9BuFAdzqQRYN3RIVkdgH6\nO8UySM5E+wfrx+SVDrzXp9iEWY+GqtEVpUikwPwof+n6Mj3tOQF8oMtu7jf+\nOy5zXiTWygJucWzU9Au3xmdK4bcDC/ml6KRHPQggoKSdyLuVXjZ1tcARQ/GD\ntjM86vbhJuE1VgZfbsTCl6vbAlkyIC0FIDZCr+d7EzrdMQktYZbgvOWF8Nk6\npKH668DYIjNUhBAvFBvDxUDiQMOkp2sUCCG2dnF36oEUZCyY2m5L8DmuTcBs\n2LIlIgn02nJrk7Wnv9bYhb6XwawgWwLmhAdjIkzyFOf4cxBErJpjv58I0CQ4\n3u54\r\n=Eh0u\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDvyp8Qk2i5k3IScVGQ15d5Ohb+HeH67FlPupzVyls7uQIgN+VwoxuYCRLOkPRsBFZhOIr8JtgcamZPMo1c8LjLP68="}]},"maintainers":[{"name":"leolobeto","email":"leolobeto@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/alfa-rest-server_0.1.1_1547444495150_0.8070944834400122"},"_hasShrinkwrap":false},"0.1.2":{"name":"@alfa-wells/alfa-rest-server","version":"0.1.2","description":"Preconfigured server for REST APIs","main":"src/index.js","scripts":{"test":"mocha --recursive"},"repository":{"type":"git","url":"git+https://github.com/llobeto/alfa-rest-server.git"},"author":{"name":"leolobeto"},"license":"ISC","bugs":{"url":"https://github.com/llobeto/alfa-rest-server/issues"},"homepage":"https://github.com/llobeto/alfa-rest-server#readme","dependencies":{"body-parser":"^1.18.3","compression":"^1.7.3","express":"^4.16.4"},"gitHead":"bde48dad0b56443d70e9496513133a0c25ca1ae1","_id":"@alfa-wells/alfa-rest-server@0.1.2","_npmVersion":"6.4.1","_nodeVersion":"10.12.0","_npmUser":{"name":"leolobeto","email":"leolobeto@gmail.com"},"dist":{"integrity":"sha512-5XQkFDLKwLUBCWu522+NKaqVE5aU4k36D4+WrRv/eZhcsybp8tTONv/n08l086Bx0KpbhoYrt9bWYjrX6DwPIQ==","shasum":"0de23270a5ca7f49cb80c9148d3fefc83ca30f98","tarball":"https://registry.npmjs.org/@alfa-wells/alfa-rest-server/-/alfa-rest-server-0.1.2.tgz","fileCount":7,"unpackedSize":7501,"npm-signature":"-----BEGIN PGP SIGNATURE-----\r\nVersion: OpenPGP.js v3.0.4\r\nComment: https://openpgpjs.org\r\n\r\nwsFcBAEBCAAQBQJcPFU3CRA9TVsSAnZWagAAUmEP/i/h4U16tnCmAtsaegs2\nj+aq0rYQO1xBRJyQT8RitXNomiJFYxEk1rfUyCSY8XhSczF5H6DfgjfpV4R/\n/Y3UMT8Sr6dUcLRXGn2G/1FJDn60FbOKMctzE6kyyGhPRtDp7z8LlvvRLITI\nd5zZG89/RZpa94UTwjZT70xKyGr+AJ7ubHwyGod+eqttl3FFjkmekPrLnXhh\nCO16hGb9MsmsKa0aWx5qTLjI8Bvl3UOssqw+9ywGy0vQxKBhVulRWcztLvhd\niBWiN5rn+320KKCWggECo5xSAGIktEscZkO19pI89HR/pR5oBCJJNXK6eelx\n/Ya6pw/iLzrNWN53D4g73Kxkn67cmavBqMhmJKhW/9CUDxHU+0uaiTpe1Bb6\nV8iij700875+4jDaemLAR/rQFB/Du1+Z7zq53FAV3nFzHAWzKGt0jlPGrImC\n/mQeNSUCicVXiWS9IQhkCcoJL+PmO72y9lgMRMSLbmlz8i5AO/JVWgv91ldi\n1WLPdPHQPPF2b2UndLnrbQZ7m/Fd/ntEWIetWw25LzFcohMEoivsypv3wnF4\nDMFTJzwDGir0lyPyFmKg/e0kUVBBRzcgsPRHcqbjZoHLe4X3zFoJCTJl4FDu\nELr615kRNtGOje2ISPI5M+m1apwGyoW5+hrRMMZIRUmL6RXn2Dy9TqBZcY3z\nrKQF\r\n=zmHP\r\n-----END PGP SIGNATURE-----\r\n","signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEQCIB0kt57rIka+TuaTZnpZ9G+G2J3lUvhsDteYTqHcCmUoAiBzMPA6aBYJdpbboDSuolUVGX7S0Eo7PwB5JbPWVWePjA=="}]},"maintainers":[{"name":"leolobeto","email":"leolobeto@gmail.com"}],"directories":{},"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/alfa-rest-server_0.1.2_1547457847113_0.8837260429311262"},"_hasShrinkwrap":false}},"time":{"created":"2019-01-14T04:52:05.427Z","0.1.0":"2019-01-14T04:52:05.784Z","modified":"2022-04-04T12:42:05.600Z","0.1.1":"2019-01-14T05:41:35.281Z","0.1.2":"2019-01-14T09:24:07.286Z"},"maintainers":[{"name":"leolobeto","email":"leolobeto@gmail.com"}],"description":"Preconfigured server for REST APIs","homepage":"https://github.com/llobeto/alfa-rest-server#readme","repository":{"type":"git","url":"git+https://github.com/llobeto/alfa-rest-server.git"},"author":{"name":"leolobeto"},"bugs":{"url":"https://github.com/llobeto/alfa-rest-server/issues"},"license":"ISC","readme":"# alfa-rest-server\r\nA preconfigured Server for Alfa REST APIs\r\n\r\n## Install\r\n```\r\nnpm install @alfa-wells/alfa-rest-server --save\r\n```\r\n\r\n## Use\r\n\r\n### Create an Express App\r\nUse the syntax:\r\n```\r\nRestServer.createApp(<port>, <logger>, [, <allowedOrigins>])\r\n```\r\nParameters:\r\n- `port`: Required. A port number to listen to\r\n- `logger`: Required. An Alfa-Logger compatible instance\r\n- `allowedOrigins`: Optional. Default value is `\"*\"`. Value of the `Access-Control-Allow-Origin` header used for CORS preflight request.\r\n\r\nExample:\r\n```js\r\nconst RestServer = require('@alfa-wells/alfa-rest-server')\r\n\r\n// You will need a logger\r\nlet logger = require('@alfa-wells/alfa-logger')('my-server')\r\n\r\n let app = RestServer.createApp(8080, logger)\r\n \r\n// Add your routes\r\napp.get('/people/:id', function (req, res) {\r\n\t\t// ...\r\n})\r\n````\r\n\r\n### Util\r\nUtilities for REST API coding. Currently:\r\n- `Util.getId(<request>[, id-parameter = \"id\"])`: Retrieves the string value of a URL parameter. Throws a bad request ServerError if parameter is not in the URL or if it's not a non-empty string.\r\n\r\n```js\r\nconst Util = require('@alfa-wells/alfa-rest-server').Util\r\n\r\n// ... create your app\r\n\r\napp.get('/people/:id', function (req, res) {\r\n\tlet id = getId(req)\r\n\t// Do something with the person id\r\n})\r\n\r\n\r\napp.get('/reports/:type', function (req, res) {\r\n\tlet type = getId(req, 'type')\r\n\t// Do something with the report type\r\n})\r\n```\r\n\r\n### ServerError\r\nSubclass of Javascript `Error`. Throw a `ServerError` in your request handlers.\r\n\r\n#### Custom error\r\nUse constructor to create.\r\n```\r\nnew ServerError(<message>[, <status-code>])\r\n```\r\nParameters:\r\n- `message`: A text message or an Error instance.\r\n- `status-code`: Optional. HTTP status code of the error. Status 500 will be used by default.\r\n\r\n#### Commmon Server Errors\r\nUse static methods to create.\r\n- `ServerError.internal()`: Creates an HTTP 500 error (Internal Server Error).\r\n- `ServerError.badRequest()`: Creates an HTTP 400 error (Bad Request).\r\n- `ServerError.unauthorized()`: Creates an HTTP 401 error (Unauthorized).\r\n- `ServerError.forbidden()`: Creates an HTTP 403 error (Forbidden).\r\n- `ServerError.notFound()`: Creates an HTTP 404 error (Not Found).\r\n\r\nExample:\r\n```js\r\nconst ServerError = require('@alfa-wells/alfa-rest-server').ServerError\r\n\r\n// In a request handler\r\nthrow ServerError.badRequest()\r\n```\r\n\r\n#### Methods\r\n##### Or\r\nIf the given error is an instance of ServerError, returns it's argument. Otherwise return this.\r\n```\r\nserviceError.or(<error>)\r\n```\r\n\r\nExample:\r\n```js\r\ntry {\r\n    // some code\r\n} catch (err) {\r\n    // It throws a ServerError. If err is not a ServerError, an internal error is thrown.\r\n    throw ServerError.internal().or(err)\r\n}\r\n```","readmeFilename":"README.md"}