Sulphur
Sulphur is a simple web framework for Node.js.
Example
S = require('sulphur')
app = new S.Application()
app.listen(1337)
# GET /
app.get (req, res) ->
res.send('Hello, world!')
# GET /api/users/
app.get 'api', 'users', (req, res) ->
users = [
{username: 'aardvarrk', age: 17},
{username: 'john', age: 18}
]
res.sendJSON(users)
# POST /posts/42/comments/
app.post 'posts', ':id', 'comments', (req, res) ->
post_id = req.parameters['id']
# TODO: Save comment.
res.send('Comment posted!')
Routing
The default router takes a variable number of arguments. If you prefer
it to take one argument that is a /
-separated string, you can use a
custom router like this:
S = require('sulphur')
class Router extends S.Router
addRoute: (method, path, handler) ->
segments = (segment for segment in path.split('/') when segment != '')
super(method, segments..., handler)
app = new S.Application({router: new Router()})
app.listen(1337)
# GET /posts/:id/comments/
app.get '/posts/:id/comments/', (req, res) ->
res.send(something)
To do
- Call rendering engine.
- Provide an interface for rendering engines.
- Server static files.