Socket
Book a DemoInstallSign in
Socket

copperhead

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
Package was removed
Sorry, it seems this package was removed from the registry

copperhead

Connect compatible router middleware that supports content negotiation

0.2.1-1
unpublished
latest
Source
npmnpm
Version published
Maintainers
1
Created
Source

Copperhead

Copperhead is a connect compatible router middleware that supports content negotiation.

Installation

npm install copperhead

Usage

The router object has a method for each HTTP method. Each method needs at least a handler function that gets req und res as parameters. If the function returns nothing, the next middleware will be used. If the function returns a string or object it will be used as response with an appropriate content type.

Optionally a method takes a path and a content type. The path variables are exposed to the this object of the handler.

router.method [path], [content type], (req, res) ->

So for example if we want to use the GET method at the path /users/:name for the content type text/html we would do

router.get '/users/:name', 'text/html', (req, res) ->
	'Hello user '+@name+'!'

A more complete example

connect = require 'connect'

router = require 'copperhead'

app = connect()
app.use connect.logger 'dev'
app.use router

router.get '/foo', ->
	'bar!'

router.get ->
	'Hello World!'

router.get 'application/json', ->
	hello: "World!"

router.get 'text/html', ->
	'<!DOCTYPE html><html><head><title>Hello World!</title></head><body></body>Hello!</html>'

app.listen 3000

Available Methods

HTTP 1.1

get, post, put, delete, options, patch

WebDAV

connect, trace, copy, lock, mkcol, move, propfind, proppatch, unlock, report, mkactivity, checkout, merge

Custom

Use router.route to create a custom route. route takes the arguments

  • method
  • path
  • mimetype
  • middleware
app = connect()
app.use connect.logger 'dev'
app.use router

router.route 'custom', '/', '*/*', ->
	"I'm custom!"

app.listen 3000

Similar Projects

FAQs

Package last updated on 18 Aug 2012

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.