Thanks to visit codestin.com
Credit goes to github.com

Skip to content
/ magenta Public

Generate flexible REST endpoints and controllers from Mongoose models in your Restify app

License

Notifications You must be signed in to change notification settings

umayr/magenta

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Magenta

Usage:

'use strict';

// Require restify and mongoose
const restify = require('restify');
const mongoose = require('mongoose');
// Require package.json
const pkg = require('./package.json');
// Require Magenta
const Magenta = require('magenta');

// Set up server details
let server = restify.createServer({
  name: pkg.name,
  version: pkg.version
});
server.use(restify.acceptParser(server.acceptable));
server.use(restify.authorizationParser());
server.use(restify.queryParser());
server.use(restify.bodyParser());
server.use(restify.CORS());

// Create a schema
let schema = new mongoose.Schema({name: 'string', size: 'string'});
let Tank = mongoose.model('Tank', schema);

// Instantiate Mongoose connection
mongoose.connect('mongodb://localhost/test');

// Instantiate Magenta
new Magenta(server, mongoose);

// Start server
server.listen(3000, function () {
  console.log('%s listening at %s', server.name, server.url);
});

Example:

$ curl --data="name=foo&size=0" localhost:3000/tank
# { success: true}

$ curl -s localhost:3000/tank
# { "name": "foo", "size": 0}

Note:

This is a work in progress, so almost everything is messy as well as API is going to change a lot. Feature requests and bug reports are pretty much appreciated at this time.

License:

MIT

About

Generate flexible REST endpoints and controllers from Mongoose models in your Restify app

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published