Mavericks is a simple RESTful API wrapper around the ExpressJS framework utilizing mongoose as the schema generator, and connection to your MongoDB instance
Run npm install --save mavericks
to add mavericks to your project.
Once installed, you can initialize an ExpressJS app with the Mavericks default settings in your app.js
/server.js
by:
var Mavericks = require("mavericks");
var app = new Mavericks();
// Do some stuff to your express server
// ...
// Start our server
app.listen(3000, function(){
console.log("Express server listening on port 3000")
})
- type:
string
- default:
path.resolve(__dirname, 'models')
This is the path to your Mongoose Schema Files
- type:
string
- default:
'mongodb://@localhost:27017/data'
This is the path to your MongoDB
- type:
string
- default:
'dev'
module.exports = {
name: String,
email: String
};
This basic example simply exposes a new object to be required and ran through mongoose.Schema
In order to modify the base routes used by Mavericks, simply expose your model schema as a function, and Mavericks will pass in our express instance so route overrides/addition can be made
Note: This requires mongoose to be installed as a dependency if you would like to access your model
var mongoose = require("mongoose");
var Schema = mongoose.Schema;
module.exports = function(app){
var schema = {
name: String,
email: String
}
var model = new Schema(schema);
app.get("my_model/", function(req, res, next){
// some arbitrary get method used in place
// of a default get route
mongoose.model('Model', model).find({}, function(e, results){
// ...
})
});
return schema;
}
By default Mavericks creates all the RESTful routes required by an API
- type:
Array
- return:
objects of the collection
- id:
id of the object
- return_type:
Object
- return:
object from the collection. Empty object if nothing
- id*:
comma separated list of ids
- return_type:
Array
- return:
objects form the requested _ids
- return_type:
Object
- return:
The saved model with _id
- id:
id of the object to update
- return_type:
String
- return:
success
/error
- id:
id of the object to delete
- return_type:
String
- return:
success
/error
- id*:
comma separated list of ids to delete
- return_type:
String
- return:
success
/error
Mavericks' test suite utilizes gulp to start a mongod
instance, and expressjs
server instance importing test schemas into Mavericks, and the runs a series of mocha
tests. The src can be found at test/
.
To run the tests
git clone git@github.com:morriswchris/mavericks
npm install
npm test
If you would just like to test locally, you can also start the test server by running npm start
and the express server will start up at 0.0.0.0:3000
(Note: this will require a running mongodb
service on the default port)
All contributions welcome. Please fork and submit a pull request ... suggestions are also welcome!