npm.io
1.2.0 • Published 2 years ago

@rayo/send

Licence
MIT
Version
1.2.0
Deps
0
Size
4 kB
Vulns
0
Weekly
14
Stars
208
@rayo/send

Install

__CODE_BLOCK_0__gt; npm i @rayo/send

Use

import rayo from 'rayo';
import send from '@rayo/send';

rayo({ port: 5050 })
  .through(send())
  .get('/hello/:user', (req, res) => {
    res.send({
      message: `Hello ${req.params.user}. I was sent with headers!`
    });
  })
  .start();

send will attach itself to the ServerResponse (a.k.a res) and be callable as res.send().

res.send() will try to guess the content-type based on the payload and send the appropriate headers. It will also send a status code and end the response.

Note: res.send() will incur a tiny performance hit due to the guess work and the headers being written with every response.

API

send()

Currently, it does not take any arguments.

License

MIT