Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
luiseduardobrito committed Aug 29, 2013
1 parent 9358bdc commit a161d85
Showing 1 changed file with 3 additions and 114 deletions.
117 changes: 3 additions & 114 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,118 +27,7 @@ npm run-script start-server
npm run-script debug-server
```

### API
### Help and Documentation

The node-web-cluster is shipped with a MVC api ready to work, as simple as this:

/api/controllers/user.js

```javascript
policy(req, res).check("authenticated", function() {

var _user = req.cookies.user;

if(_user.password)
delete _user.password;

res.json({

result: "success",
user: _user
});

})

```

#### Models

Are defined in ```/api/models/``` as ```[user]_model.js```. Example: ```/api/models/user_model.js```.

File structure:
```javascript
module.exports = {

name: {

required: true,
type: "string"

},

email: {

required: true,
type: "email"

},

password: {

required: true,
type: "password"

},

access_token: {

required: true,
type: "string"

},

role: {

required: true,
type: "string",
default: "user"
},

toJSON: function(_this){

delete _this.password;
return JSON.stringify(_this);
}
}
```

Then, you can create a new object based on the model you defined above.

```javascript
var user = model.create("user", {

name: "name",
email: "[email protected]",
password: "abcd1234",
access_token: "01234567890"

});

console.log(user.email); // prints: "[email protected]"
```

#### Controllers

Are defined in ```/api/controllers/``` as ```[name].js```. Example: ```/api/controllers/user.js```.

File structure: ```/api/controllers/test.js```

```javascript
module.exports = {

// route: /test
index: function(req, res) {
res.json({
test: "ok"
})
},

// route: /test/get
get: function(req, res) {
res.json({
test: "ok"
})
},

}
```
* [Wiki](https://github.com/luiseduardobrito/node-web-cluster/wiki)
* [Issues](https://github.com/luiseduardobrito/node-web-cluster/issues)

0 comments on commit a161d85

Please sign in to comment.