# sendme

> Express middleware used to convert json and res.send in multiple formats

Latest version **0.1.7** (published 2015-11-25) · MIT license · 0 weekly downloads

## Install

```sh
npm install sendme
pnpm add sendme
yarn add sendme
bun add sendme
```

## 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.1.7 |
| Published | 2015-11-25 |
| First published | 2015-10-26 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 3 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Matt Snow |
| Maintainers | mfsnow |
| Keywords | expressjs, send, json, xml, csv, xlsx, delimited, text |

## Links

- npm: https://www.npmjs.com/package/sendme
- npm.io page: https://npm.io/package/sendme

## Dependencies (3)

- [excel4node](https://npm.io/package/excel4node.md) ^0.2.21
- [js2xmlparser](https://npm.io/package/js2xmlparser.md) ^1.0.0
- [tabular-json](https://npm.io/package/tabular-json.md) ^0.1.3

## Alternatives

- [@mapbox/jsonlint-lines-primitives](https://npm.io/package/@mapbox/jsonlint-lines-primitives.md) — 5.3M weekly downloads
- [reftools](https://npm.io/package/reftools.md) — 3.5M weekly downloads
- [@hey-api/openapi-ts](https://npm.io/package/@hey-api/openapi-ts.md) — 3.5M weekly downloads
- [@mapbox/geojson-rewind](https://npm.io/package/@mapbox/geojson-rewind.md) — 2.4M weekly downloads
- [turbo-stream](https://npm.io/package/turbo-stream.md) — 1.7M weekly downloads

## Recent versions

- 0.1.7 (latest) — 2015-11-25
- 0.1.6 — 2015-11-25
- 0.1.5 — 2015-11-19
- 0.1.4 — 2015-11-19
- 0.1.3 — 2015-10-27
- 0.1.2 — 2015-10-27
- 0.1.1 — 2015-10-27
- 0.1.0 — 2015-10-26

## README

# Sendme ExpressJS Middleware
ExpressJS middleware. Send response containing data. Format in `JSON`, `XML`, `csv`, `xlsx`, `html`, and `text`.

## Install
```
$ npm install sendme
```

## Usage
```js
var sendme = require('sendme');

app.use(sendme(config)); // Attaches sendme(data) to res.

app.use(function(req, res) {
  var json;

  // Do work.

  res.sendme(json);
});
```

### require('sendme')(config)
`config` (optional) is a JSON object containing formatting configurations. The `config` is passed to the `delimit()` function in [tabular-json](https://github.com/mfsnow/tabular-json#delimit). Pass format-specific options using a sub-object (e.g. as `{xlsx: {includeHeaders: false}}`), and non-specific options to the base `config` object.

#### Config Examples
```js
var config = {
  includeHeaders: false,
  sort: ['id'],
  txt: {
    separator: ';',
    stringWrap: '"'
  }
};
```
See [tabular-json](https://github.com/mfsnow/tabular-json) for more details on config options

### Formats
sendme will send the response in various formats. Either specify a content type using the `Accept` header, or append a format extension to the end of the `req.path`. A format extension will always override the `Accept` header.
- `.json` - Content-Types: `application/json`
  - `application/json` is the primary response type.
- `.xml` - Content-Types: `application/xml`, `text/xml`
- `.xlsx` - Content-Types: `application/vnd.openxmlformats-officedocument.spreadsheetml.sheet`
- `.csv` - Content-Types: `application/csv`
- `.html` - Content-Types: `text/html`
- `.txt` - Content-Types: `text/plain`

### Examples
Specify a format in the url path:
```http
GET /foos/1.xml HTTP/1.1
Host: example.com
```

```js
var data = {
  id: 1,
  type: 'widget'
};
res.sendme(data);
```

Response:
```http
HTTP/1.0 200 OK
Content-Type: text/xml

<?xml version="1.0" encoding="UTF-8" ?>
<data>
  <id>1</id>
  <type>widget</type>
</data>
```

Also, specify a format in the `Accept` parameter:
```http
GET /foos HTTP/1.1
Host: example.com
Accept: application/csv
```

Response:
```http
HTTP/1.0 200 OK
Content-Type: application/csv

"id","type"
1,"widget"
2,"gadget"
```

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