Skip to content

Commit

Permalink
Updated package.json and added support for PATCH
Browse files Browse the repository at this point in the history
  • Loading branch information
tarruda committed Jan 18, 2013
1 parent 66f1882 commit cf0458b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"author": "Thiago de Arruda <tpadilha84@gmail.com>",
"name": "flask-router",
"version": "0.0.3",
"version": "0.0.4",
"description": "Flask-inspired routing system for node and connect.\nNice if you just need a routing system without depending on connect, or need routing middleware without all features provided by express.",
"main": "./lib/router.js",
"repository": {
Expand Down
5 changes: 4 additions & 1 deletion src/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -234,6 +234,7 @@ class Router
POST: []
PUT: []
DELETE: []
PATCH: []
@compiled = false


Expand Down Expand Up @@ -390,8 +391,10 @@ module.exports = (parsers) ->
r.register('put', 'PUT', pattern, handlers...)
del: (pattern, handlers...) ->
r.register('del', 'DELETE', pattern, handlers...)
patch: (pattern, handlers...) ->
r.register('patch', 'PATCH', pattern, handlers...)
all: (pattern, handlers...) ->
for method in ['GET', 'POST', 'PUT', 'DELETE']
for method in ['GET', 'POST', 'PUT', 'DELETE', 'PATCH']
r.register('all', method, pattern, handlers...)
return handlers
}
17 changes: 11 additions & 6 deletions test/router.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ describe 'Rules', ->
(req, res, next) -> res.write('p3'); next(),
(req, res, next) -> res.write('p4'); res.end()

router.patch '/patch-route', (req, res) ->
res.write('patched!')
res.end()

it 'should match simple patterns', (done) ->
app.request()
.get('/$imple/.get/pattern$')
Expand All @@ -46,16 +50,17 @@ describe 'Rules', ->
it 'should pipe request through all handlers', (done) ->
app.request()
.get('/^pattern/that/uses/many/handlers')
.end (res) ->
res.body.should.eql('part1part2part3')
done()
.expect('part1part2part3', done)

it 'should cancel pipeline when handler ends the request', (done) ->
app.request()
.get('/cancel')
.end (res) ->
res.body.should.eql('p1p2')
done()
.expect('p1p2', done)

it 'can also be registered to patch methods', (done) ->
app.request()
.patch('/patch-route')
.expect('patched!', done)


describe 'Pathname normalization', ->
Expand Down
2 changes: 1 addition & 1 deletion test/support/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Module dependencies.
*/
var EventEmitter = require('events').EventEmitter
, methods = ['get', 'post', 'put', 'delete', 'head']
, methods = ['get', 'post', 'put', 'delete', 'head', 'patch']
, connect = require('connect')
, http = require('http');

Expand Down

0 comments on commit cf0458b

Please sign in to comment.