0.1.1 • Published 11 years ago

torr v0.1.1

Weekly downloads
52
License
-
Repository
github
Last release
11 years ago

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

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);
0.1.1

11 years ago

0.1.0

11 years ago

0.0.8

11 years ago

0.0.7

11 years ago

0.0.6

11 years ago

0.0.5

11 years ago

0.0.4

11 years ago

0.0.3

11 years ago

0.0.2

11 years ago

0.0.1

11 years ago