Coder Social home page Coder Social logo

coreagame / entropy.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from chevalun/entropy.js

0.0 2.0 0.0 81 KB

entropy is a simple RESTful server in front of a MongoDB instance using node.js, Express, Connect and Mongoose.

Home Page: http://www.pierre-minnieur.de/

License: MIT License

entropy.js's Introduction

README

entropy is a simple RESTful server in front of a MongoDB instance using node.js, Express and Mongoose.

DEPENDENCIES

INSTALLATION

Clone the Github repository. Update the vendor libraries:

$> git clone git://github.com/pminnieur/entropy.js.git
$> sh update_vendors.sh

You can run an entropy instance just by starting it with the node command:

node entropy.js

CONFIGURATION

Copy the config.json.sample file to config.json and modify it to fit your needs.

USAGE

You can use entropy without any models, but I recommend to have a schema for each of your models. You can put your Mongoose models in the /models directory. Here's an example of an simple user model:

// models/user.js
var mongoose = require("mongoose").Mongoose;

mongoose.model("user", {
  properties: ["username", "email"],
  cast: {
    username: String,
    email: String
  },
  indexes: ["username", "email"]
});

That's it. You can now find, read, create, modify and remove user objects via REST, just by calling the appropriate URLs. The routing schema is very simple:

Find

GET /:collection

Read

GET /:collection/:id

Create

POST /:collection?collection[field1]=value1&collection[field2]=value2...

Modify

POST /:collection/:id?collection[field1]=value1&collection[field2]=value2...

Remove

DELETE /:collection/:id

NOTE: the collection[] array must be named like the model you want to access, thus for creating or modifying a user you must use it like this: ?user[username]=foo&user[email]=bar

Finding documents

You can specifiy what you want to find with the following parameters:

Querying

GET /:collection?query[field1]=value1&query[field2]=value2&...

Sorting

GET /:collection?order[field1]=asc|desc&order[field2]=asc|desc&...

Pagination

GET /:collection?limit=5&offset=5

CUSTOMIZATION

If you want to overload the default behavior of the REST controllers, simply put your own in the /controllers directory. Here's an example for a customized user controller which removes users' email address from the response:

// controllers/user.js
var app = modules.parent.exports.app,
    db = modules.parent.exports.db;
    
app.get('/user', function(req, res) {
  db.model('user').find().all(function(users) {
    ret = [];
    users.forEach(function(user) {
      user = user.toObject();
      delete user.email;
      ret.push(user);
    });

    res.header('Content-Type', 'application/json');
    res.send(ret, 200);
  })
});

LICENSE

For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

entropy.js's People

Contributors

chevalun avatar

Watchers

James Cloos avatar  avatar

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.