torr
v0.1.1
Published
RESTful application development framework for Node.
Downloads
15
Readme
torr
Install
npm install torr
Hello, World!
var torr = require('torr'),
connect = require('connect'),
http = require('http');
var app = torr()
.get('/', function(req, res) {
res.end('hello, world');
})
.get('/ping', function(req, res) {
res.end('pong');
});
app.topic('/orders', 'Everything about the orders')
.get('/{orderId:int}', function(req, res, orderId) {
res.end('order: ' + orderId);
})
.post('/', function(req, res) {
res.end('adding new order!');
});
// middleware container
var container = connect()
.use(connect.logger('dev'))
.use(connect.query())
.use('/api', app);
http.createServer(container).listen(8677);
Features
- Compatible with Connect-based Middleware
- Automatic Swagger spec (v1.2) generation
More on Swagger spec generation
var torr = require('torr'),
connect = require('connect'),
http = require('http');
var app = torr({
swagger: {
info: {
title: "Sample App for Swagger Demo",
description: "This is a sample app for Swagger support demo."
},
models: {
Order: {
id: { type: 'int', desc: 'Order ID' },
petId: { type: 'int', desc: 'Pet ID' },
customerName: { desc: "Name of the customer" },
quantity: { type: 'int', desc: 'Order quantity', default: 1 },
notes: { type: 'str', desc: 'Additional notes on the order' }
}
}
}
});
app.topic('/store', 'operations for store')
.get('/order/{orderId:int}', {
summary: 'Find purchase order by ID',
desc: 'For valid response try integer IDs with value <= 5. Anything above 5 or nonintegers will generate API errors',
nickname: 'getOrderById',
params: {
orderId: { type: 'int', desc: 'test description' }
},
type: 'Order',
errors: {
400: 'invalid order id',
404: 'order not found'
}
}, function(req, res, orderId) {
res.end('order: ' + orderId);
})
.post('/order', {
summary: 'Place an order',
nickname: 'postOrder',
params: {
body: { type: 'Order', desc: 'order placed for purchasing the pet' }
},
type: 'Order',
errors: {
400: 'invalid order'
}
}, function(req, res) {
res.end('order placed');
});
// middleware container
var container = connect()
.use(connect.logger('dev'))
.use(connect.query())
.use('/api', app);
http.createServer(container).listen(8677);