1.0.3 • Published 11 years ago

media-types v1.0.3

Weekly downloads
100
License
-
Repository
github
Last release
11 years ago

media-types build status

handle multiple media types

Example

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

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

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

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

Example with custom error handling

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

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

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

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

Installation

npm install media-types

Tests

npm test

Contributors

  • Raynos

MIT Licenced

1.0.3

11 years ago

1.0.2

11 years ago

1.0.1

11 years ago

0.1.0

12 years ago