Skip to content

Create REST resources and controllers with thinky and Express or Restify

License

Notifications You must be signed in to change notification settings

mbroadst/thinky-rest

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

76 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

thinky-rest

Build Status Dependency Status

Create REST resources and controllers with thinky and express or restify

Getting Started

var thinky = require('thinky')(),
    rest = require('thinky-rest'),
    http = require('http');

// Define your models
var User = test.db.createModel('users', {
  username: thinky.type.string().required(),
  birthday: thinky.type.type.date().required()
});

// Initialize server
var server, app;
if (process.env.USE_RESTIFY) {
  var restify = require('restify');

  app = server = restify.createServer()
  app.use(restify.queryParser());
  app.use(restify.bodyParser());
} else {
  var express = require('express'),
      bodyParser = require('body-parser');

  app = express();
  app.use(bodyParser.json());
  app.use(bodyParser.urlencoded({ extended: false }));
  server = http.createServer(app);
}

// Initialize thinky-rest
rest.initialize({
  app: app,
  thinky: thinky
});

// Create a REST resource
var userResource = rest.resource({
  model: User,
  endpoints: ['/users', '/users/:id']
});

// Start the server and access your rest routes
server.listen(function() {
  var host = server.address().address,
      port = server.address().port;

  console.log('listening at http://%s:%s', host, port);
});

About

Create REST resources and controllers with thinky and Express or Restify

Resources

License

Stars

Watchers

Forks

Packages

No packages published