respondjs
v0.3.0
Published
Format-dependent response library for nodejs, simillar to the respond_to command in rails.
Downloads
151
Readme
RespondJS
respondjs is a simple package for defining format-based HTTP responses. It is inspired
by the ´respond_to´ rails function. You can define a callback for any response MIME format.
The respondjs module will select the appropriate response format by checking the
req.params.format
value and the HTTP Accept header respectively. After a format has been
chosen, the callback registered for that format will be called.
var app = require("express")();
var respond = require("respondjs");
var response = respond().to("text", function(req, res, format) { res.send("hello world"); })
.json(function(req, res, format) { res.json({hello: "world"}); });
response.respond(res);