Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/joakimbeng/micro-compress
Compression for HTTP microservices built with Micro
https://github.com/joakimbeng/micro-compress
Last synced: 1 day ago
JSON representation
Compression for HTTP microservices built with Micro
- Host: GitHub
- URL: https://github.com/joakimbeng/micro-compress
- Owner: joakimbeng
- Created: 2016-09-22T10:13:37.000Z (about 8 years ago)
- Default Branch: master
- Last Pushed: 2017-01-27T20:48:56.000Z (almost 8 years ago)
- Last Synced: 2024-10-14T13:18:34.428Z (26 days ago)
- Language: JavaScript
- Size: 1.95 KB
- Stars: 43
- Watchers: 2
- Forks: 3
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-micro - micro-compress - Compression for HTTP microservices. (Modules / Utilities)
README
# micro-compress
[![Build status][travis-image]][travis-url] [![NPM version][npm-image]][npm-url] [![XO code style][codestyle-image]][codestyle-url]
> Compression for HTTP microservices built with [Micro](https://github.com/zeit/micro)
## Installation
Install `micro-compress` using [npm](https://www.npmjs.com/):
```bash
npm install --save micro-compress
```## Usage
### Module usage
Just wrap your [Micro](https://github.com/zeit/micro) HTTP microservice with this module:
```javascript
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`](https://github.com/expressjs/compression) module are passed as the first parameter:
```javascript
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`](https://github.com/expressjs/compression) |
| fn | `function` | The request handler to wrap |For available options see [`compression`'s options](https://github.com/expressjs/compression#options).
## License
MIT © [Joakim Carlstein](http://joakim.beng.se)
[npm-url]: https://npmjs.org/package/micro-compress
[npm-image]: https://badge.fury.io/js/micro-compress.svg
[travis-url]: https://travis-ci.org/joakimbeng/micro-compress
[travis-image]: https://travis-ci.org/joakimbeng/micro-compress.svg?branch=master
[codestyle-url]: https://github.com/sindresorhus/xo
[codestyle-image]: https://img.shields.io/badge/code%20style-XO-5ed9c7.svg?style=flat