Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

handle multiple media types

branch: master

Fetching latest commit…

Cannot retrieve the latest commit at this time

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

Something went wrong with that request. Please try again.