stream-response
v1.0.4
Published
Respond with json, html, text, etc. or redirect. Extend headers easily.
Downloads
6
Readme
SYNOPSIS
Respond with json
, html
, text
, or redirect
. Extend headers easily.
BUILD STATUS
USAGE
const Response = require('stream-response')
const http = require('http')
http.createServer((req, res) => {
const response = Response(res)
response.json(200, { message: 'OK' })
}).listen(8080)
response.html(401, '<h1>Not Allowed</h1>')
response.text(418, 'Tea Time!')
ABSOLUTE REDIRECTS
Defaults to 302
.
response.redirect(req, 'https://google.com')
response.redirect(302, req, 'https://google.com')
RELATIVE REDIRECTS
response.redirect(req, '/login')
response.redirect(301, req, '/login')
EXTEND HEADERS
Extend the headers for each request with the headers()
method.
response.headers({ 'content-type': 'application/x-www-form-urlencoded' })
response.end(200, { name: 'danzig', number: 13 })