0.9.0 • Published 12 years ago

teller v0.9.0

Weekly downloads
38
License
-
Repository
github
Last release
12 years ago

#teller Simple node.js webserver.
Dependencies: crossroads, ejs, filed, formidable, wrench.

Build Status

Installation

npm install teller
var app = require('teller')
app.get('/', function(req, res) {
  res.json({ foo: 'bar' })
}).listen(1234)

Routing

See crossroads.addRoute for more documentation on route patterns. Teller only supports string patterns, and named variables are available in req.route.

app.get(route, callback)

Add an GET route with callback.

app.get('/', function(req, res) {
  res.send('<h1>Hello world!</h1>')
})

app.post(route, callback)

Add a POST route with callback.

app.post('/add', function(req, res) {
  res.json(req.body)
})

app.delete(route, callback)

Add a DELETE route with callback.

app.delete('/image', function(req, res) {
  res.json(req.body)
})

app.settings(settings)

Settings for template rendering and static file serving.

app.settings({
  template: { dir: __dirname+'/templates', 404: '404.ejs' },
  static: { route: '/public', dir: __dirname+'/public' }
})

app.listen(port)

Begin accepting connections on the specified port.

app.listen(1234)

Request

req.route

Contains named variables (see Routing) as key-value pairs.

app.get('/:foo:', function(req, res) {
  console.log(req.route.foo)
  // GET /bar would log 'bar'
})

req.query

Contains a parsed query string for GET requests.

app.get('/qs', function(req, res) {
  console.log(req.query.foo)
  // GET /qs?foo=bar would log 'bar'
})

req.body

Contains a parsed form body for POST & DELETE requests.

app.post('/form', function(req, res) {
  console.log(req.body.foo)
  // POST /form foo=bar would log 'bar'
})

Response

res.json(obj , statusCode)

Render the object as json.

app.get(route, function(req, res) {
  res.json({ foo: bar })
})

res.redirect(url , statusCode)

Redirect to another url.

app.get(route, function(req, res) {
  res.redirect('/login')
})

res.render(template [, data , statusCode])

Render the specified template. Template directory must be specified in app.settings().

app
  .settings({ dir: __dirname+'/templates' })
  .get(route, function(req, res) {
    res.render('template.ejs', data, statusCode)
  })

res.send(data [, contentType , statusCode])

Renders a string, with optional Content-Type header and status code.

app.get(route, function(req, res) {
  res.send('<h1>hello</h1>')
})

res.show404()

If settings.template['404'] is supplied, renders a custom 404 page, otherwise sends the default 404 page.

app.get(route, function(req, res) {
  res.show404(data)
})
0.9.0

12 years ago

0.8.0

12 years ago

0.7.0

12 years ago

0.6.0

12 years ago

0.5.0

12 years ago

0.4.0

12 years ago

0.3.0

12 years ago

0.2.0

12 years ago

0.1.0

12 years ago