Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/heapwolf/stream-response
Respond with `json`, `html`, `text`, or `redirect`. Extend headers easily.
https://github.com/heapwolf/stream-response
Last synced: 25 days ago
JSON representation
Respond with `json`, `html`, `text`, or `redirect`. Extend headers easily.
- Host: GitHub
- URL: https://github.com/heapwolf/stream-response
- Owner: heapwolf
- Created: 2016-11-28T12:08:04.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-09-05T13:27:36.000Z (about 7 years ago)
- Last Synced: 2024-10-18T16:59:01.857Z (26 days ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 9
- Watchers: 3
- Forks: 4
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# SYNOPSIS
Respond with `json`, `html`, `text`, or `redirect`. Extend headers easily.# BUILD STATUS
[![Build Status](https://travis-ci.org/0x00A/stream-response.svg?branch=master)](https://travis-ci.org/0x00A/stream-response)# USAGE
```js
const Response = require('stream-response')
const http = require('http')http.createServer((req, res) => {
const response = Response(res)
response.json(200, { message: 'OK' })
}).listen(8080)
``````js
response.html(401, 'Not Allowed
')
``````js
response.text(418, 'Tea Time!')
```## ABSOLUTE REDIRECTS
Defaults to `302`.```js
response.redirect(req, 'https://google.com')
response.redirect(302, req, 'https://google.com')
```## RELATIVE REDIRECTS
```js
response.redirect(req, '/login')
response.redirect(301, req, '/login')
```## EXTEND HEADERS
Extend the headers for each request with the `headers()` method.```js
response.headers({ 'content-type': 'application/x-www-form-urlencoded' })
response.end(200, { name: 'danzig', number: 13 })
```