# prefer-js

> HTTP Prefer Header Middleware

Latest version **0.0.3** (published 2015-09-17) · MIT license · 0 weekly downloads

## Install

```sh
npm install prefer-js
pnpm add prefer-js
yarn add prefer-js
bun add prefer-js
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.0.3 |
| Published | 2015-09-17 |
| First published | 2015-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | James M Snell |
| Maintainers | jasnell |
| Keywords | Prefer, HTTP, Middleware |

## Links

- npm: https://www.npmjs.com/package/prefer-js
- Repository: https://github.com/jasnell/prefer.js
- Issues: https://github.com/jasnell/prefer.js/issues
- npm.io page: https://npm.io/package/prefer-js

## Recent versions

- 0.0.3 (latest) — 2015-09-17
- 0.0.2 — 2015-07-28
- 0.0.1 — 2015-07-28

## README

## HTTP Prefer Middleware

Connect middleware for the Prefer Header (http://tools.ietf.org/html/rfc7240)

Installation:
```
npm install prefer-js
```

Example:
```
var app = require('express')();
app.use(require('prefer'));

app.get('/', function(req,res) {
  var prefer = req.prefer;

  if (prefer.handling === 'strict') {
    // strict handling
  } else if (prefer.handling === 'lenient') {
    // lenient handling
  }

  if (prefer.respondAsync) {
    // client prefers async response
  }

  if (prefer.wait) {
    var n = prefer.wait;
    // client will wait n seconds for a response
  }

  if (prefer.return === 'minimal') {
    // client prefers a minimal response
  } else if (prefer.return === 'representation') {
    // client prefers a representation response
  }

  if (prefer.foo) {
    // client specified the 'foo' extension preference
  }

  res.preferenceApplied('handling');
  res.preferenceApplied('return');

  // if application of a preference results in a varied response,
  // be sure to set the Vary header in the response also

  res.status(204).end();
});
app.listen(port);
```

---
_Source: https://npm.io/package/prefer-js · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
