# express-ensure-ctype

> Express middleware for blocking unwanted Content-Type(s).

Latest version **1.0.0** (published 2018-01-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install express-ensure-ctype
pnpm add express-ensure-ctype
yarn add express-ensure-ctype
bun add express-ensure-ctype
```

## Health

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

Positive: no vulnerabilities.

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

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.0.0 |
| Published | 2018-01-28 |
| First published | 2014-01-20 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | nemtsov@gmail.com |
| Maintainers | nemtsov |
| Keywords | express, middleware, content-type, mime |

## Links

- npm: https://www.npmjs.com/package/express-ensure-ctype
- npm.io page: https://npm.io/package/express-ensure-ctype

## Alternatives

- [@sindresorhus/slugify](https://npm.io/package/@sindresorhus/slugify.md) — 3.7M weekly downloads
- [solid-js](https://npm.io/package/solid-js.md) — 2.7M weekly downloads
- [expo-glass-effect](https://npm.io/package/expo-glass-effect.md) — 2.5M weekly downloads
- [nanoassert](https://npm.io/package/nanoassert.md) — 780.8K weekly downloads
- [@ffmpeg/ffmpeg](https://npm.io/package/@ffmpeg/ffmpeg.md) — 529.5K weekly downloads

## Recent versions

- 1.0.0 (latest) — 2018-01-28
- 0.1.0 — 2014-01-20

## README

# Ensure Content-Type [![Build Status](http://travis-ci.org/nemtsov/express-ensure-ctype.png)](http://travis-ci.org/nemtsov/express-ensure-ctype) [![NPM version](https://badge.fury.io/js/express-ensure-ctype.svg)](http://badge.fury.io/js/express-ensure-ctype)

Tiny [express](https://github.com/visionmedia/express) middleware for blocking 
unwanted Content-Type(s). When a type doesn't match, a 400 error is
sent to the client, otherwise the next middleware is called.

Usage:

```javascript
const express = require('express');
const ensureCtype = require('express-ensure-ctype');

const ensureJson = ensureCtype('json');
const app = express();

app.post('/', ensureJson, (req, res) => {
  res.json(req.body);
});

app.listen(3000);
```

Result:

```
curl -i -XPOST http://localhost:3000/

HTTP/1.1 415 Unsupported Media Type
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
Content-Length: 37
ETag: W/"25-LXMJEoIT4KTBnB71Rca6CNA/pM0"
Date: Sun, 28 Jan 2018 00:45:38 GMT
Connection: keep-alive

"Unsupported Content-Type. Use: json"
```

```
curl -i -H 'Content-type: application/json' -d '{}' http://localhost:3000/

HTTP/1.1 200 OK
X-Powered-By: Express
Content-Type: application/json; charset=utf-8
ETag: W/"7-ofL7/ixK2BdJzQOAtzUpXQb50MQ"
Date: Sun, 28 Jan 2018 00:44:58 GMT
Connection: keep-alive
Transfer-Encoding: chunked
```

An array can also be used for multiple content-types:

```javascript
ensureCtype(['csv', 'text']);
```

License
-------

[MIT](/LICENSE)

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