1.0.0 • Published 7 years ago

@appjumpstart/mercury-send v1.0.0

Weekly downloads
-
License
ISC
Repository
-
Last release
7 years ago

mercury-send

An Express/Connect-compatible middleware for sending HTTP responses

npm page appjumpstart chat

About

mercury-send is a super simple middleware that provides (or overrides) a res.send function that you can use in other middleware/route handlers. You can use it with Node's http.Server, Express, or any connect-compatible framework. To get the most benefit, you'll want to use it in tandem with mercury-schema which will provide mercury-send with a stringify function based on a pre-compiled response schema.

Installation

❯ npm install @appjumpstart/mercury-send --save

Usage

const mercurySend = require('@appjumpstart/mercury-send')

// ...

// Use the mercury-send middleware to more easily send responses.
app.use(mercurySend)

// Use res.send in your route-handler to send object that are converted to
// JSON using JSON.stringify or perhaps a stringify function provided by
// mercury-schema.
app.get('/', (req, res) => res.type('json').send({ message: 'Hello!' }))

Acknowledgement

mercury-send is completely modeled around some of the features within the excellent Fastify framework.