{"_id":"response","_rev":"227672","name":"response","description":"Streaming and mutation API for HTTP responses.","dist-tags":{"latest":"0.18.0"},"maintainers":[{"name":"mikeal","email":""}],"time":{"modified":"2023-03-24T10:40:50.000Z","created":"2014-03-13T19:09:13.507Z","0.18.0":"2015-07-27T17:00:03.346Z","0.17.0":"2015-07-25T23:24:31.861Z","0.16.0":"2015-07-25T23:21:25.844Z","0.15.0":"2015-07-25T23:21:01.697Z","0.14.0":"2014-04-14T22:43:49.865Z","0.13.0":"2014-03-19T05:23:39.772Z","0.12.0":"2014-03-19T04:03:40.192Z","0.11.0":"2014-03-13T20:58:35.236Z","0.10.0":"2014-03-13T20:58:08.353Z","0.1.0":"2014-03-13T19:09:13.507Z"},"users":{},"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"repository":{"type":"git","url":"git+https://github.com/mikeal/response.git"},"versions":{"0.18.0":{"name":"response","version":"0.18.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"queuelib":"^0.3.6","request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/mikeal/response.git"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","gitHead":"a4bc88ef5fb57570a7230f09912576513895b0df","_id":"response@0.18.0","_shasum":"a1009f271733f233582de0a95fb4cbaa5ea8b206","_from":".","_npmVersion":"2.13.0","_nodeVersion":"2.4.0","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"dist":{"shasum":"a1009f271733f233582de0a95fb4cbaa5ea8b206","size":5452,"noattachment":false,"key":"/response/-/response-0.18.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.18.0.tgz"},"publish_time":1438016403346,"_hasShrinkwrap":false,"_cnpm_publish_time":1438016403346,"_cnpmcore_publish_time":"2021-12-16T21:08:55.309Z"},"0.17.0":{"name":"response","version":"0.17.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"queuelib":"^0.3.6","request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/mikeal/response.git"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","gitHead":"e4ac73274c7064f7496665aea8e20365277a9f05","_id":"response@0.17.0","_shasum":"27271414111022f9e5a46ec1d3e7527ccee416c1","_from":".","_npmVersion":"2.8.3","_nodeVersion":"1.8.1","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"dist":{"shasum":"27271414111022f9e5a46ec1d3e7527ccee416c1","size":5440,"noattachment":false,"key":"/response/-/response-0.17.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.17.0.tgz"},"publish_time":1437866671861,"_hasShrinkwrap":false,"_cnpm_publish_time":1437866671861,"_cnpmcore_publish_time":"2021-12-16T21:08:55.679Z"},"0.16.0":{"name":"response","version":"0.16.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"queuelib":"^0.3.6","request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/mikeal/response.git"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","gitHead":"a8b3d29a3455110d5020e60f3187d93df0d7f3a9","_id":"response@0.16.0","_shasum":"0378cb2e25571abc884c83d43ea56d25098c696d","_from":".","_npmVersion":"2.8.3","_nodeVersion":"1.8.1","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"dist":{"shasum":"0378cb2e25571abc884c83d43ea56d25098c696d","size":5440,"noattachment":false,"key":"/response/-/response-0.16.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.16.0.tgz"},"publish_time":1437866485844,"_hasShrinkwrap":false,"_cnpm_publish_time":1437866485844,"_cnpmcore_publish_time":"2021-12-16T21:08:55.942Z"},"0.15.0":{"name":"response","version":"0.15.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"queuelib":"^0.3.6","request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"git+https://github.com/mikeal/response.git"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","gitHead":"eed7ffece9d5bff2fa35f1013b39db67cc6f9002","_id":"response@0.15.0","_shasum":"2fd15d01940b642af4e1463933889cbb422896fd","_from":".","_npmVersion":"2.8.3","_nodeVersion":"1.8.1","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"dist":{"shasum":"2fd15d01940b642af4e1463933889cbb422896fd","size":5438,"noattachment":false,"key":"/response/-/response-0.15.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.15.0.tgz"},"publish_time":1437866461697,"_hasShrinkwrap":false,"_cnpm_publish_time":1437866461697,"_cnpmcore_publish_time":"2021-12-16T21:08:56.137Z"},"0.14.0":{"name":"response","version":"0.14.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"https://github.com/mikeal/response"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","_id":"response@0.14.0","dist":{"shasum":"066352ff3e6b026d0475809407663b4686fd2696","size":4513,"noattachment":false,"key":"/response/-/response-0.14.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.14.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"publish_time":1397515429865,"_hasShrinkwrap":false,"_cnpm_publish_time":1397515429865,"_cnpmcore_publish_time":"2021-12-16T21:08:56.782Z"},"0.13.0":{"name":"response","version":"0.13.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"https://github.com/mikeal/response"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","_id":"response@0.13.0","dist":{"shasum":"dc224dd4c7b4a233b11bcaf30d086c3e9a7bfb8b","size":4487,"noattachment":false,"key":"/response/-/response-0.13.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.13.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"publish_time":1395206619772,"_hasShrinkwrap":false,"_cnpm_publish_time":1395206619772,"_cnpmcore_publish_time":"2021-12-16T21:08:57.070Z"},"0.12.0":{"name":"response","version":"0.12.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0","caseless":"^0.3.0","best-encoding":"^0.1.1"},"devDependencies":{"request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"https://github.com/mikeal/response"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","_id":"response@0.12.0","dist":{"shasum":"fd2030feec76ed6df668aa00a37067ca36e61d41","size":3693,"noattachment":false,"key":"/response/-/response-0.12.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.12.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"publish_time":1395201820192,"_hasShrinkwrap":false,"_cnpm_publish_time":1395201820192,"_cnpmcore_publish_time":"2021-12-16T21:08:57.345Z"},"0.11.0":{"name":"response","version":"0.11.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0"},"devDependencies":{"request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"https://github.com/mikeal/response"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","_id":"response@0.11.0","dist":{"shasum":"7b988cdefb3885678f77319ddeeb534730d31df8","size":2193,"noattachment":false,"key":"/response/-/response-0.11.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.11.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"publish_time":1394744315236,"_hasShrinkwrap":false,"_cnpm_publish_time":1394744315236,"_cnpmcore_publish_time":"2021-12-16T21:08:57.564Z"},"0.10.0":{"name":"response","version":"0.10.0","description":"Streaming and mutation API for HTTP responses.","main":"index.js","directories":{"test":"tests"},"dependencies":{"mime":"~1.2.11","bl":"~0.7.0"},"devDependencies":{"request":"~2.34.0","tape":"~2.10.2"},"scripts":{"test":"tape tests/*.js"},"repository":{"type":"git","url":"https://github.com/mikeal/response"},"keywords":["http","response","request"],"author":{"name":"Mikeal Rogers","email":"mikeal.rogers@gmail.com"},"license":"Apache2","bugs":{"url":"https://github.com/mikeal/response/issues"},"homepage":"https://github.com/mikeal/response","_id":"response@0.10.0","dist":{"shasum":"07c08603223602b28089271ccbe47a25a564632b","size":2193,"noattachment":false,"key":"/response/-/response-0.10.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.10.0.tgz"},"_from":".","_npmVersion":"1.4.4","_npmUser":{"name":"mikeal","email":"mikeal.rogers@gmail.com"},"maintainers":[{"name":"mikeal","email":""}],"publish_time":1394744288353,"_hasShrinkwrap":false,"_cnpm_publish_time":1394744288353,"_cnpmcore_publish_time":"2021-12-16T21:08:57.833Z"},"0.1.0":{"name":"response","description":"beefs up and extends node's http.ServerResponse object","version":"0.1.0","author":{"name":"Marak Squires","email":"marak.squires@gmail.com"},"repository":{"type":"git","url":"http://github.com/marak/response.git"},"main":"./lib/response","engines":{"node":">= 0.2.0"},"_id":"response@0.1.0","_nodeSupported":true,"_npmVersion":"0.2.6alpha-1","_nodeVersion":"v0.3.2-pre","dist":{"shasum":"ecc573993bdd39457fce2ca5e7c47a5715532a91","size":2143,"noattachment":false,"key":"/response/-/response-0.1.0.tgz","tarball":"http://name.csiicloud.com:7001/response/download/response-0.1.0.tgz"},"directories":{},"publish_time":1394737753507,"maintainers":[{"name":"mikeal","email":""}],"_hasShrinkwrap":false,"_cnpm_publish_time":1394737753507,"_cnpmcore_publish_time":"2021-12-16T21:08:58.046Z"}},"readme":"## Quick Example\n\n    response.json({result:'error',missing_keys:['email']}).status(400).pipe(res)\n    \n    // headers are { 'content-type': 'application/json',\n    // date: 'Mon, 12 May 2014 12:57:31 GMT',\n    // connection: 'keep-alive',\n    // 'transfer-encoding': 'chunked' } \n    // statusCode is 400 \n    // body is { result: 'error', missing_keys: [ 'email' ] }\n \n\n## Response\n\nThe basic idea is to build [request](https://github.com/mikeal/request) for HTTP Responses.\n\nThis whole package is still beta.\n\n### files\n\n```javascript\nvar server = http.createServer(function (req, res) {\n  var f = fs.createReadStream('file.js')\n  if (req.url === '/test.js') return f.pipe(response()).pipe(res)\n})\n```\n\nWhen pipeing files to `response` it will lookup the mime type and set the propert content-type header for whatever file extension you send it.\n\n### html, json, txt\n\n```javascript\nvar server = http.createServer(function (req, res) {\n  if (req.url === '/') return response.html('<html>Hello World</html>').pipe(res)\n  if (req.url === '/sitemap.html') {\n    var f = fs.createReadStream('sitemap')\n    return f.pipe(response.html()).pipe(res)\n  }\n  if (req.url === '/something.json') return response.json({test:1}).pipe(res)\n  if (req.url === '/something.txt') return response.txt('some test').pipe(res)\n})\n```\n\n### .error(err[, statusCode])\n\n```javascript\nr.error(new Error('Uh Oh!')).pipe(res)\n```\n\n```javascript\nr.error(555).pipe(res)\n```\n\n```javascript\nr.error(new Error('Uh Oh!'), 501).pipe(res)\n```\n\nIn addition, errors emitted on the stream piped to `response` will be passed through the same API and are accesssible in `views`.\n\n## gzip and deflate compression\n\nThe `compress` and `gzip` keys in an options object are used for compression.\n\n```javascript\nvar server = http.createServer(function (req, res) {\n  var f = fs.createReadStream('file.js')\n  if (req.url === '/file.js') return f.pipe(response({compress:req})).pipe(res)\n})\n```\n\nYou can pass an HTTP Request object and the best compression, if any, will be chosen for you. Alternatively you can pass `\"gzip\"` or `\"deflate\"` to forcce compression of the response stream.\n\nThis compression option is compatible with every other feature in `response` and will work whether you do file streaming, html, json, or even using views. When passing a view, string or buffer to `response` the second argument is used as the options object.\n\n```javascript\nvar server = http.createServer(function (req, res) {\n  if (req.url === '/') return response.html('<html>Nope</html>', {compress:req}).pipe(res)\n})\n```\n\n## status codes and headers\n\n`response` also has an extended version of node core's HTTP Response API.\n\nAll headers setting and checking is done caseless while preserving the original casing when first set. This way you never accidentally send two of the same header but can still support broken clients that check for specific caseing.\n\n#### .statusCode\n\nSet the statusCode property to send the HTTP status code. This is a non-destructive way to send the status code.\n\n```javascript\nvar r = response()\nr.statusCode = 500\nr.html('<html>Error</html>')\n```\n\n#### .setHeader(key, value[, clobber=true])\n\nDefaults to clobbering (overwritting) existing values but when disabled will concatenate values.\n\n```javascript\nr.setHeader('X-Blah', 'somehost.com')\n```\n\n#### .setHeader(headers)\n\nSet multiple headers by passing an object.\n\n```javascript\nr.setHeader({'x-blah': 'somehost', 'x-blah2': 'anotherhost.com'})\n```\n\n#### .getHeader(key)\n\nYou can retreive a header by its key, use this method instead of directly accessing the headers object to avoid caseing constraints.\n\n```javascript\nr.getHeader('content-type')\n```\n\n#### .hasHeader(key)\n\nCheck if a header is already set. If one is set the header key will be returned (which is important because it may have different caseing).\n\n```javascript\nr.hasHeader('content-type')\n```\n\n### views (very experimental)\n\n```javascript\nfunction view (e, data, cb) {\n  if (e) return cb(e)\n  cb(null, '<html>' + data + '</html>')\n}\n\nvar server = http.createServer(function (req, res) {\n  var r = response(view)\n  r.pipe(res)\n  if (req.url === '/test1') return r.html('test')\n})\n```\n\nThis is how you would easily support something like a template system. TODO: example.\n\n### Credits\n\nMad props to @marak who handed over the \"response\" package in npm that he registered way back in the day.\n","_attachments":{},"homepage":"https://github.com/mikeal/response","bugs":{"url":"https://github.com/mikeal/response/issues"},"license":"Apache2"}