GithubHelp home page GithubHelp logo

mbroadst / thinky-rest Goto Github PK

View Code? Open in Web Editor NEW
14.0 3.0 5.0 79 KB

Create REST resources and controllers with thinky and Express or Restify

License: MIT License

Makefile 0.40% JavaScript 99.60%

thinky-rest's Introduction

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);
});

thinky-rest's People

Contributors

mbroadst avatar olekongithub avatar thekiwi avatar

Stargazers

 avatar Crazy avatar Jaguarperson avatar Milenko avatar Dmitrii Vasilev avatar Branden Dane avatar Starter avatar Doug Brown avatar Pedro Mathias Nakibar avatar Clayton Cavaleiro avatar Ng Thong avatar  avatar Clear Bear avatar Paul Day avatar

Watchers

James Cloos avatar Ng Thong avatar  avatar

thinky-rest's Issues

Error when querying by secondary index and sorting

I'm using thinky-rest 0.1.3 and I've discovered if you have a query that uses the secondary index, as well as sorting, RethinkDB throws an error:
Expected type TABLE but found SELECTION: SELECTION ON table(foo)

An example request that causes this error would be:
http://localhost:3000/api/foo?bar=123&sort=baz
(where bar is the secondary index)

I'm new to RethinkDB but I think this is due to the _applyOrderBy function being executed (and appending orderBy to the query) before the secondary index based criteria is added to the query.

Apart from this, thinky-rest is great! I might have a go forking and creating a PR myself if I get some time.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.