caminte-generator

1.0.4 • Public • Published

Dependency Status NPM version

CaminteJS RestFul server

Fast, unopinionated, minimalist restful server for node and express based on caminte orm.

CaminteJS ORM db adapters:

mysql, sqlite3, postgres, mongodb, redis, riak, couchdb(nano), rethinkdb, tingodb

Installation

$ npm install -g caminte-generator

Quick Start

The quickest way to get started with caminte-generator is to utilize the executable cjs(1) to generate an application as shown below:

Create the app:

$ npm install -g caminte-generator
$ cjs -i test && cd ./test

Install dependencies:

$ npm install

Edit ./config/index.js file, to configure the connection to the database server.

Create model:

$ cjs -g User name email password desciption:text created:date

Run server:

$ cjs -s

Calling a REST server with Command Line cURL

Create User:

$ curl -X POST http://localhost:3000/api/users -i -H "Content-type: application/json" -d "{\"name\":\"Alex Gora\",\"created\":\"2014-01-01\"}"
# or
$ curl -X POST http://localhost:3000/api/users -i -d "name=Alex%20Gora&created=2014-01-01"

Update User:

$ curl -X PUT http://localhost:3000/api/users/1 -i -H "Content-type: application/json" -d "{\"pass\":\"6r87uyfGFTg\",\"email\":\"example@example.com\"}"
# or
$ curl -X PUT http://localhost:3000/api/users/1 -i -d "pass=6r87uyfGFTg&email=example@example.com"

Get Users:

$ curl -X GET http://localhost:3000/api/users -i -H "Content-type: application/json" -d "{\"skip\":\"0\",\"limit\":\"10\",\"sort\":\"id:desc\"}" 
# or
$ curl -X GET http://localhost:3000/api/users -i -d "skip=0&limit=10&sort=id:desc" 

Delete User:

$ curl -X DELETE http://localhost:3000/api/users/1 -i

Search:

$ curl -X GET http://localhost:3000/api/users -i -H "Content-type: application/json"  -d "{\"search\":\"name:alex\"}"
# or
$ curl -X GET http://localhost:3000/api/users -i -d "search=name:alex" 

Usage

$ cjs [options] [dir]

Options

-h, --help                  output usage information
-V, --version               output the version number
-i, --init <appname>        create caminte application
-p, --prefix <prefix>       api url prefix defaults v1
-g, --generate <modelname]  generate data model
-s, --server                runs caminte server
-a, --adapter               database adapter (mysql|redis|etc...)
-j, --jade                  add jade engine support (defaults to ejs)
-H, --hogan                 add hogan.js engine support
-c, --css <engine>          add css <engine> support (less|stylus|compass) (defaults to plain css)
-f, --force                 force on non-empty directory

Examples

# create new restful application
$ cjs -i Test -a mysql -j

# create model
$ cjs -g Post active:bool name:string desc:text created:date

Routes

will provide the following routes:

method        route                    action 
------------------------------------------------------------
GET           /api/:table                  index      
GET           /api/:table/:id              show       
POST          /api/:table                  create    
PUT           /api/:table/:id              update      
DELETE        /api/:table/:id              destroy    
DELETE        /api/:table                  destroyall  

Directory structure

On initialization directories tree generated, like that:

.
|-- bin
|   `-- www
|-- config
|   `-- index.js
|-- lib
|   |-- inflection.js
|   |-- tools.js
|   `-- xml.js
|-- models
|   `-- User.js
|-- public
|   |-- css
|   |   `-- ...
|   |-- js
|   |   `-- ...
|   `-- img
|       `-- ...
|-- test
|   |-- routes
|   |   `-- ...
|   |-- models
|   |   `-- ...
|   `-- units
|       `-- ...
|-- app.js
`-- package.json

Recommend extensions

  • TrinteJS - Javascrpt MVC Framework for Node.JS
  • CaminteJS - Cross-db ORM for NodeJS
  • 2CO - is the module that will provide nodejs adapters for 2checkout API payment gateway.

License

(The MIT License)

Copyright (c) 2014 Aleksej Gordejev <aleksej@gordejev.lv>

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

Resources

Analytics Bitdeli Badge

Package Sidebar

Install

npm i caminte-generator

Weekly Downloads

13

Version

1.0.4

License

none

Last publish

Collaborators

  • biggora