零依赖性HTTP响应功能
零依赖性HTTP响应功能
Node.js HTTP工具
共36Star
详细介绍
http-responders
Zero-dependency HTTP response functions.
Supports:
json
redirect
stream
file
download
Example
const { json, redirect, stream, file, download } = require('http-responders')
http.createServer((req, res) => {
// Respond with JSON
json(res, { beep: 'boop' })
// Redirect
redirect(req, res, 'https://example.com/')
// Respond with a generic stream
stream(res, fs.createReadStream('file.txt'))
// Respond with a file (+ content length)
file(res, 'file.txt')
// Make the browser download the file
download(res, 'file.txt)
})
Installation
$ npm install http-responders
API
.json(res, json)
.redirect(req, res, location)
await .stream(res, stream)
await .file(res, path, [fsOpts])
await .download(res, path, [fsOpts])
Sponsors
Development of this module is sponsored by:
License
MIT
-
13517 Star
-
2431 Star
-
0 Star
-
3008 Star
-
610 Star
-
4775 Star
-
2473 Star
-
13 Star
-
0 Star