Rest
A rest-adapter for Mongoose-Express applications
Install
Usage
Rest helps reduce the number of controller functions in your application. It also powers up your document and sub-document search and filtering capabilities with the popular api-query-params
package. Moreover, it registers several middleware functions for handling authentication, validation and redaction out-of-the-box.
Schema options
To configure REST, simply add three options to your Mongoose schema.
restify
: A string to indicate which HTTP options to enable (or use a wildcard for all);collectionPluralName
: The name of property to list documents in the Response payload;collectionSingularName
: The name of the property on single-resource calls in the Response payload.
Example
The sample would generate the REST endpoints documented below.
Get all examples
GET
api.com/rest-examples
The collection name is used in the URL. For the sake of brevity, we'll only document the most common queries available. For more information, consult api-query-params
.
Query Parameters
Create an example
POST
api.com/rest-examples
All top-level properties in the schema are exposed to the API body unless set as "systemOnly." The validation of the schema is copied into a validation layer for Express using m2e-validator
and express-validator
.
Request Body
Last updated