@rayo/send

✈️ Rayo's response sender

Usage no npm install needed!

<script type="module">
  import rayoSend from 'https://cdn.skypack.dev/@rayo/send';
</script>

README

@rayo/send

Install

gt; npm i @rayo/send

Use

const rayo = require('rayo');
const send = require('@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 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