call-a3 / micro-accepts

A decorator for use with micro to handle requests differently depending on content negotiation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

micro-accepts

NPM Travis Codecov Greenkeeper badge David David Dev

micro decorator to vary request handling based on the Accept header of the request.

Installing

# npm
npm install -s micro-accepts

# yarn
yarn add micro-accepts

Usage

import accepts from 'micro-accepts'

export default accepts({
  async json(req, res) {
    // this method will handle requests that prefer json
  },
  async ['application/xml+custom'](req, res) {
    // this method will handle requests that prefer application/xml+custom
  },
  async text(req, res) {
    // this method will handle requests that accept text. This is also the default if no more specific types are accepted
  },
})

About

A decorator for use with micro to handle requests differently depending on content negotiation

License:MIT License


Languages

Language:JavaScript 100.0%