dreamcatcher
v0.1.2
Published
Create a REST Web Service based on models defined in JSON format
Downloads
5
Maintainers
Readme
dreamcatcher
dreamcatcher is a tool that extends the knex-schemer and bookshelf-factory schema definition format to produce a rest web service using restify to perform CRUD operations on resources stored in a relational database. At its core, dreamcatcher uses bookshelf and knex to perform the actual database access, and bookshelf-factory to produce the models.
- See the WIKI for full documentation
- And the Change Log for what's new
Install
npm install -g dreamcatcher
Usage
// create a database connection config
var config = {
"client": "mysql",
"connection": {
"host": "127.0.0.1",
"user": "db",
"password": "password",
"database": "test",
"charset": "utf8"
}
};
// require the package passing the config
var dream = require('dreamcatcher')(config);
Basic Example
JavaScript
// create a database connection config
var config = {
"client": "mysql",
"connection": {
"host": "127.0.0.1",
"user": "db",
"password": "password",
"database": "test",
"charset": "utf8"
},
rest: {
"port": 8081
}
};
// require the package and pass the db connection config
var dream = require('dreamcatcher')(config);
var type = dream.schemer.constants.type;
// define a schema in schemer format that has been extended to use
// bookshelf-factory and dreamcatcher field extensions
var schema = {
survivor: {
id: {type: type.integer, primary: true, increments: true, views: ['summary']},
name: {type: type.string, size: 200, views: ['summary']},
groups: {belongsToMany: 'group', views: ['summary']},
station_id: {type: type.integer},
station: {belongsTo: 'station', views: ['summary']},
_rest: {
methods: {
HEAD: {},
GET: {},
POST: {},
PUT: {},
DELETE: {}
}
}
}
};
// create the routes
var routes = dream.getRoutes(schema);
// run the server
dream.run(routes);
This will create the routes and methods
- (HEAD, GET, POST) http://host.domain.com:8081/survivors
- (HEAD, GET, PUT, DELETE) http://host.domain.com:8081/survivors/:id
Tools
Created with Nodeclipse (Eclipse Marketplace, site)
Nodeclipse is free open-source project that grows with your contributions.