media-types

handle multiple media types

npm install media-types
13 downloads in the last week
29 downloads in the last month

media-types build status

handle multiple media types

Example

var http = require("http")
var mediaTypes = require("media-types")

http.createServer(mediaTypes({
    "application/json": sendJson
    , "text/html": sendHtml
})).listen(8080)

function sendJson(req, res) { res.end("json") }

function sendHtml(req, res) { res.end("html") }

Example with custom error handling

var http = require("http")
    , mediaTypes = require("media-types")

http.createServer(mediaTypes, {
    "application/json": sendJson
    , "text/html": sendHtml
    , default: function (req, res) {
        res.statusCode = 415
        res.end("I refuse to handle you")
    }
})).listen(8080)

function sendJson(req, res) { res.end("json") }

function sendHtml(req, res) { res.end("html") }

Installation

npm install media-types

Tests

npm test

Contributors

  • Raynos

MIT Licenced

npm loves you