@polka/send
An extremely simple HTTP Response helper — not limited to Polka!
@polka/send-type
instead~
Install
$ npm install --save @polka/send
Usage
const send = require('@polka/send');
module.exports = function (req, res, next) {
if (!req.getHeader('authorization')) {
return send(res, 401, 'Token required!');
}
next();
}
API
send(res, code, data, headers)
res
Type: ServerReponse
The outgoing HTTP response.
code
Type: Number
Default: 200
The statusCode
for your response.
data
Type: String
Default: ''
The body
for your response. Defaults to the statusText
for the given statusCode
.
Important: You are responsible for ensure your
data
is a string!
For inferredContent-Type
s and response-casting, check out@polka/send-type
instead!
headers
Type: Object
Default: {}
The headers
for your response.
Support
Any issues or questions can be sent to the Polka repo, but please specify that you are using @polka/send
.
License
MIT © Luke Edwards