# stream-response

> Respond with json, html, text, etc. or redirect. Extend headers easily.

Latest version **1.0.4** (published 2017-09-05) · ISC license · 0 weekly downloads

## Install

```sh
npm install stream-response
pnpm add stream-response
yarn add stream-response
bun add stream-response
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.4 |
| Published | 2017-09-05 |
| First published | 2016-11-28 |
| Weekly downloads | 0 |
| License | ISC |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 1 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | hij1nx |
| Maintainers | hij1nx |

## Links

- npm: https://www.npmjs.com/package/stream-response
- npm.io page: https://npm.io/package/stream-response

## Dependencies (1)

- [json-stringify-safe](https://npm.io/package/json-stringify-safe.md) ^5.0.1

## Recent versions

- 1.0.4 (latest) — 2017-09-05
- 1.0.3 — 2017-09-05
- 1.0.2 — 2017-03-16
- 1.0.1 — 2017-03-16
- 1.0.0 — 2016-11-28

## 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, '<h1>Not Allowed</h1>')
```

```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 })
```

---
_Source: https://npm.io/package/stream-response · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
