:bicyclist: Express REST resources as middleware mountable anywhere
by developitLast 12 weeks · 0 commits
2 of 6 standards met
Repository: developit/resource-router-middleware. Description: :bicyclist: Express REST resources as middleware mountable anywhere Stars: 122, Forks: 17. Primary language: JavaScript. Languages: JavaScript (100%). License: BSD-3-Clause. Homepage: http://npm.im/resource-router-middleware Topics: express, javascript, middleware, rest, rest-api. Open PRs: 1, open issues: 8. Last activity: 7y ago. Community health: 42%. Top contributors: developit, fadeenk, nikrich, gitter-badger.
JavaScript
Currently, when the is undefined the router always defaults to vs The latter result accounts for request methods without the need for the URI fragment.
import resource from 'resource-router-middleware'; import multer from 'multer'; let uploads = multer({ dest: 'uploads/' }); export default resource({ middleware: [ uploads.single('avatar'); ], // then use it in a route: create({ body, files }, res) { console.log(files); res.json(body); } }); (Reference from #6) I'm trying to use uploads.single() my parameter and form name has matched but my console.log(files); return undefined. How can I Accept a single file with the name fieldname?
Feature request There are cases where the user may not need to preload resource data by and just perform the action (ex: DELETE, PATCH, PUT) on the resource itself. A good example of this is a call to a database using a defined (non-public) token. Use example Now, this could be handled by creating a separate router middleware specific to this use-case. But in the effort to consolidate routes for a given , while taking advantage of actions and injection provided by this library, it would be nice if it supported both scenarios. Code update Currently, this expression prevents the route from being loaded when the resource doesn't exist. A simple solution to this would be to make this value optional and rely on to determine whether this value should be defined (as it does already) and how it should be handled. Let me know your thoughts on this?