handle multiple media types
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
test
.gitignore
.travis.yml
LICENCE
Makefile
README.md
index.js
package.json

README.md

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