JSPM

micro-compress

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 25092
  • Score
    100M100P100Q146996F
  • License MIT

Compression for HTTP microservices built with Micro

Package Exports

  • micro-compress

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (micro-compress) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

micro-compress

Build status NPM version XO code style

Compression for HTTP microservices built with Micro

Installation

Install micro-compress using npm:

npm install --save micro-compress

Usage

Module usage

Just wrap your Micro HTTP microservice with this module:

const {send, json} = require('micro');
const compress = require('micro-compress');

module.exports = compress(async (req, res) => {
    const body = await json(req);
    send(res, 200, body);
});

Options for the compression module are passed as the first parameter:

const {Z_BEST_COMPRESSION} = require('zlib');
const {send, json} = require('micro');
const compress = require('micro-compress');

module.exports = compress({level: Z_BEST_COMPRESSION}, async (req, res) => {
 const body = await json(req);
 send(res, 200, body);
});

API

compress(opts, fn)

Name Type Description
opts object Optional. Options passed to compression
fn function The request handler to wrap

For available options see compression's options.

License

MIT © Joakim Carlstein