{"id":21405348,"url":"https://github.com/karimsa/peddler","last_synced_at":"2025-03-16T16:51:03.900Z","repository":{"id":57321698,"uuid":"34354805","full_name":"karimsa/peddler","owner":"karimsa","description":"a lightweight REST framework","archived":false,"fork":false,"pushed_at":"2017-06-05T03:12:14.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"v0","last_synced_at":"2025-03-11T21:04:00.653Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/karimsa.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2015-04-21T22:10:17.000Z","updated_at":"2017-06-04T19:33:57.000Z","dependencies_parsed_at":"2022-08-25T21:01:03.312Z","dependency_job_id":null,"html_url":"https://github.com/karimsa/peddler","commit_stats":null,"previous_names":[],"tags_count":7,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Fpeddler","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Fpeddler/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Fpeddler/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/karimsa%2Fpeddler/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/karimsa","download_url":"https://codeload.github.com/karimsa/peddler/tar.gz/refs/heads/v0","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243902293,"owners_count":20366259,"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":[],"created_at":"2024-11-22T16:24:35.098Z","updated_at":"2025-03-16T16:51:03.839Z","avatar_url":"https://github.com/karimsa.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Peddler\n\na lightweight REST framework.\n\n[![NPM](https://nodei.co/npm/peddler.png?downloads=true\u0026downloadRank=true\u0026stars=true)](https://nodei.co/npm/peddler/)\n\n## Usage\n\nTo use this framework, install it via npm (`npm install --save peddler`) and configure your router:\n\n```javascript\n// instantiate a new instance of peddler\n// with some options\nvar app = require('peddler')(options)\n\n// start the web server\napp.listen()\n```\n\n## Options\n\n - **schema**: an instance of `mongoose.model` with your user info setup. The schema MUST contain the following sub-document:\n```json\n{\n  \"_peddler\": {\n    \"key\": String,\n    \"secret\": String,\n    \"rusty\": \"boolean\"\n  }\n}\n```\n - **username**: the key from which to extract the username from `UserSchema` rows. (default: 'email')\n - **password**: the key from which to extract the password from `UserSchema` rows. (default: 'password')\n - **secure**: a boolean about whether or not to use https. (default: true)\n - **auth**: a boolean about whether or not to use authentication. (default: true)\n - **http2**: a boolean about whether or not to use HTTP/2. (default: true)\n - **routes**: a JSON-based router setup or a string path to the routing folder. (default: './routes')\n - **log**: string specifying a format to use with [morgan](https://github.com/expressjs/morgan). (default: yellow+bold simplified apache-like log)\n - **ssl**: a JSON object to be passed as the first argument to https.Server. (load your key/cert into this, or (default) create a folder in '.' called ssl with 'server.key' and 'server.crt')\n - **latency**: maximum latency the event loop may experience before you begin dropping connections. (default: 10)\n - **badConnections**: maximum number of connections you drop from a client before banning them with iptables. (default: 5)\n\n## Methods\n\n*The peddler object is extended from the express app instance and will, therefore, support all the express application methods/properties. It is also extended from events.EventEmitter and therefore will support events. All the events are proxied from the https server.*\n\n - **listen()**: setup a web server on next available port.\n - **listen([port])**: try to start a web server on port `[port]`.\n - **listen([start], [end])**: setup a web server on next available port after `[start]` but before `[end]`.\n\n## Routing\n\nThe route handling for peddler is a bit different from express in the sense that it focuses on a preference for exiting synchronously.\nTherefore, all route handlers will be passed the request (http.IncomingMessage) as the only parameter, and the context will be set to\nthe response object provided by express. If the method returns `undefined`, it will be assumed that the method is now gone into asynchronous\nmode and therefore the response object must be ended to return anything to the client. However, if anything else is returned, it will be stringified\n(preferring String() then using JSON.stringify()) and the response will be ended with the string.\n\nThe routing table can only choose to filter and cast any incoming request bodies by providing the types of the fields they wish to receive (all other\nfields will be ignored).\n\nSimple hello world:\n\n```javascript\nvar app = require('peddler')({\n  routes: {\n    '/hello': {\n      'params': {\n        'name': 'string'\n      },\n\n      'get': function (req) {\n        return 'Hello, ' + req.body.name;\n      }\n    }\n  }\n})\n```\n\nTry doing `curl -d \"name=world\" https://localhost/hello` and it should result in \"Hello, world\".\n\n*Like it should be, routing is not established after the server is started. The routing table is parsed into an express router when the peddler\ninstance is created. So there's no point of trying to change the routing table at runtime; it's a bad idea anyways. If you are thinking of something\nlike this, read what the [expressjs docs](http://expressjs.com/4x/api.html) have to say about params.*\n\n## License\n\nGPLv3.\n\n```\npeddler: a lightweight REST framework.\nCopyright (C) 2015 Online Health Database\n\nThis program is free software: you can redistribute it and/or modify\nit under the terms of the GNU General Public License as published by\nthe Free Software Foundation, either version 3 of the License, or\n(at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarimsa%2Fpeddler","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkarimsa%2Fpeddler","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkarimsa%2Fpeddler/lists"}