Skip to content

tasawr/pixy

Repository files navigation

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/index.js.git
$> sh update_vendors.sh

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

node index.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/post.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/post.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.

About

mobile app to shoot and share

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published