respondjs

0.3.0 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i respondjs

Weekly Downloads

18

Version

0.3.0

License

MIT

Last publish

Collaborators

  • nanobot248