@polka/send

0.4.0 • Public • Published

@polka/send npm

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: 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 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

Readme

Keywords

none

Package Sidebar

Install

npm i @polka/send

Weekly Downloads

1,612

Version

0.4.0

License

MIT

Unpacked Size

1.96 kB

Total Files

4

Last publish

Collaborators

  • lukeed