lukeed

@polka/send

An extremely simple HTTP Response helper — not limited to Polka!

✨ For a more "magical" helper, check out @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: ServerResponse

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 inferred Content-Types 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

See also

@polka/cluster(3), @polka/compression(3), @polka/parse(3), @polka/redirect(3), @polka/send-type(3), @polka/url(3), polka(3), clsx(3), @pwa/cli(3), uvu(3)