Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

sendme

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sendme

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

  • 0.1.7
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Weekly downloads
 
Created
Source

Sendme ExpressJS Middleware

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

Install

$ npm install sendme

Usage

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. 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
var config = {
  includeHeaders: false,
  sort: ['id'],
  txt: {
    separator: ';',
    stringWrap: '"'
  }
};

See 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:

GET /foos/1.xml HTTP/1.1
Host: example.com
var data = {
  id: 1,
  type: 'widget'
};
res.sendme(data);

Response:

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:

GET /foos HTTP/1.1
Host: example.com
Accept: application/csv

Response:

HTTP/1.0 200 OK
Content-Type: application/csv

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

Keywords

FAQs

Package last updated on 25 Nov 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc