2.2.0 • Published 10 months ago

http-responders v2.2.0

Weekly downloads
1
License
MIT
Repository
github
Last release
10 months ago

http-responders

Zero-dependency HTTP response functions.

Supports:

  • status
  • json
  • redirect
  • stream
  • file
  • download

Example

import { status, json, redirect, stream, file, download } from 'http-responders'

http.createServer(async (req, res) => {

  // Respond with HTTP Status
  status(res, 404)

  // Respond with JSON
  json(res, { beep: 'boop' })

  // Redirect
  redirect(req, res, 'https://example.com/')

  // Respond with a generic stream
  await stream(res, fs.createReadStream('file.txt'))

  // Respond with a file (+ content length)
  await file(res, 'file.txt')

  // Make the browser download the file
  await download(res, 'file.txt)

})

Installation

$ npm install http-responders

API

.status(res, code)

.json(res, json)

.redirect(req, res, location, code = 302)

await .stream(res, stream)

await .file(res, path, fsOpts)

await .download(res, path, fsOpts)

License

MIT

2.2.0

10 months ago

2.1.0

10 months ago

2.0.2

2 years ago

2.0.1

2 years ago

2.0.0

4 years ago

1.0.0

5 years ago