A simple tool for automatically generating REST APIs with json schemas and mongodb.
autocrudapp: app // The express application object.collection: mongohoosit // The collection object generated by the mongo driver.name: 'hoosit' // The name of the object (this will be appended to the end of path).path: '/api' // The root URL path that this API should be generated at.schema: // The json schema that should be used for validationtype: 'object'properties:name: type: 'string' required: truedescription: type: 'string'rating: type: 'integer'comments: type: 'array' items: type: 'string'additionalProperties: false;
appThe express application object. This is used to generate REST routes for GET, POST, PUT and DELETE.
collectionThe mongo collection object. This is where the API will store its data. NOTE: this tool will not ensure indexes.
nameThe name of this API's objects, this will also be appended to the end of the path param when generating routes.
pathThe root path for the routes generated by this API.
schemaThe json-schema that will be used to validate objects given to the API by POST and PUT.
autocrud// Default optionsif !bodyrating bodyrating = 1;;
Transform functions take a single parameter, which is the message body after it has been validated.
defaultTransformIf specified, this transform function will be applied to both POST and PUT operations.
postTransformIf specified, this function will be used for POST operations, overriding the defaultTransform.
putTransformIf specified, this function will be used for PUT operations, overriding the defaultTransform.
autocrud// Default optionsif reqisAuthenticated && _containsrequserroles 'administrator' next;else ressend401 'Unauthenticated';;
defaultAuthenticationIf specified, this middleware will by applied to all HTTP methods on the auto-curd route.
getAuthenticationIf specified, this middleware will be applied to the GET HTTP method. Overrides default.
postAuthenticationIf specified, this middleware will be applied to the POST HTTP method. Overrides default.
putAuthenticationIf specified, this middleware will be applied to the PUT HTTP method. Overrides default.
deleteAuthenticationIf specified, this middleware will be applied to the DELETE HTTP method. Overrides default.
autocrud// Default optionsreturn requser_id;ownerField: 'owner';
NOTE: Both of the following fields must be provided for object ownership to be enabled.
ownerIdFromReqA function that extracts the user id value from the request object. This is passed as the first param.
ownerFieldThe name of the field in each mongo document that holds the owner id.