irestful

0.0.2 • Public • Published

IRESTFUL

Gerador de RESTFul para NodeJS

Instalação e Configuração

npm install irestful
//Configure and Start iRESTFul
irestful.start({
    app  : app,
    uri_prefix  : '/REST',
    schema_path  : __dirname + '/models',
    authentication  : false
});

Insert

Method: POST or PUT
 
    URL: http://localhost:port/REST/FooSchema
    
    Parametros:
        - foofield
        - barfield
        
    Return:{
        "Meta"{
            "schema""FooSchema",
            "action""INSERT"
        },
        "Count":Number,
        "Result" : Object {..}
    }

Update

  • Necessario passar o parametro _id
Method: POST or PUT
 
    URL: http://localhost:port/REST/FooSchema
    
    Parametros:
        - _id
        - barfield
        
    Return:{
        "Meta"{
            "schema""FooSchema",
            "action""UPDATE"
        },
        "Count":Number,
        "Result" : Object {..}
    }

Delete

Method: DELETE or GET
 
    DELETE: http://localhost:port/REST/FooSchema/ObjectID
    GET: http://localhost:port/REST/FooSchema/ObjectID/delete
    
    Return:{
        "Meta"{
            "schema""FooSchema",
            "action""DELETE"
        },
        "DeletedObject" : Object {..}
    }

Search

Method: GET
 
    URL: http://localhost:port/REST/FooSchema
    
    Parametros:
        - search
        - populate
        - limit
        - page
        
    Return:{
        "Meta"{
            "schema""FooSchema",
            "action""INSERT",
            "pagination": {...},
            "search": {...},
            "populate": {...}
        },
        "Count":Number,
        "Result" : Object {..}
    }

Autenticação

Method: GET
 
    É necessario um registro na Collection AuthAPI para utilizar a autenticação de acesso
    
    Nesse modelo:
    
    { "_id" : ObjectId( "53262c54913663c90d04347c" ),
        "created" : Date( 1395010644438 ),
        "allow_collections" : [
            { "name" : "FooSchema","permissions" : ["SEARCH","INSERT","UPDATE"] },
            { "name" : "BarSchema","permissions" : ["SEARCH","DELETE","UPDATE"] }
        ],
        "allow_domains" : ["google.com"],
        "__v" : 0 
    }
 
    URL: http://localhost:port/REST/FooSchema
    
    Nesse caso a chave para a Collection FooSchema será: 53262c54913663c90d04347c
    
    Parametros:
        - search
        - irestful_api_token
        - populate
        - limit
        - page
        
    Return:{
        "Meta"{
            "schema""FooSchema",
            "action""INSERT",
            "pagination": {...},
            "search": {...},
            "populate": {...}
        },
        "Count":Number,
        "Result" : Object {..}
    }

No NodeJS

var express = require('express'),
    http = require('http'),
    path = require('path'),
    app = express(),
    mongoose = require('mongoose')
    irestful = require('irestful');
 
var Schema = mongoose.Schema
 
mongoose.connect('mongodb://localhost/base');
 
app.use(express.bodyParser())
 
//Configure and Start iRESTFul
irestful.start({
    app  : app,
    uri_prefix  : '/REST',
    schema_path  : __dirname + '/models',
    authentication  : false
});
 
http.createServer(app).listen(app.get('port')function(){
  console.log('Express server listening on port ' + app.get('port'));
});

License

MIT

Free Software, Hell Yeah!

Dependencies (0)

    Dev Dependencies (0)

      Package Sidebar

      Install

      npm i irestful

      Weekly Downloads

      2

      Version

      0.0.2

      License

      none

      Last publish

      Collaborators

      • inonjs