Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

added two more TODO tests

  • Loading branch information...
commit bb194429aa587b61cd6f28c772f271743901f593 1 parent 846175e
Tatsuhiko Miyagawa authored March 16, 2010
50  README
@@ -2,11 +2,57 @@ This is a collection of URI dispatching using Plack::Request and various CPAN mo
2 2
 
3 3
 Most examples would do:
4 4
 
5  
-  GET / => "Hello World"
  5
+  GET / => "Hello World" in text/plain
6 6
   GET /blog/{year}/{month} => Get the list of blog posts in year/month
7 7
   POST /comment => Post a comment with parameters id, name and body
8 8
 
  9
+Nice to have:
  10
+
  11
+  /blog/{year}/{month} should be limited to 4-digit year and 2-digit month
  12
+  POST to GET-only endpoints should raise 405
  13
+
9 14
 You can run tests against the dispatcher using:
10 15
 
11  
-  perl tester.pl <dispatcher.pl>
  16
+  perl tester.pl <dispatcher.psgi>
  17
+
  18
+NOTES
  19
+
  20
+Here're some notes and observations. This is not a check-no-check
  21
+comparison. When it says "Can't do ...", it doesn't necessarily mean a
  22
+minus - it means it's application's responsibility, which could mean
  23
+more flexibilities.
  24
+
  25
+dancer:
  26
+  (Dancer doesn't use Plack::Request -- here's for the comparison)
  27
+  Can use named capture and regexp based dispatching
  28
+  POST to GET endpoints gives 404 by default
  29
+
  30
+HTTP::Router::Declare:
  31
+  Can dispatch using HTTP methods as well
  32
+  (You can remove { method => 'GET' } requirement to make 405 fallbacks work)
  33
+  Can specify requirement like routes.py
  34
+
  35
+HTTPx::Dispatcher:
  36
+  Can't use HTTP method as a dispatcher rule - it's an app's responsibility
  37
+  Can't use regular expressions / requirements
  38
+
  39
+Mojolicious::Lite:
  40
+  (Mojolicious doesn't use Plack::Request -- here's for the comparison)
  41
+  Can use named capture + regexp requirement like Merb / HTTP::Router
  42
+  POST to GET endpoints gives 404 by default
  43
+
  44
+Path::Dispatcher:
  45
+  Passing PSGI env to the metadata for REQUEST_METHOD matching
  46
+  (You can omit that to make 405 fallbacks on the app work)
  47
+
  48
+Path::Router:
  49
+  Can use Moose based constraints to validate path chunks
  50
+  Can't use HTTP method as a dispatcher rule - it's an app's reponsibility
  51
+
  52
+Tatsumaki:
  53
+  Can't use HTTP method as a dispatcher rule - app handlers need to define the verbs
  54
+  Default '/' is catch-all as of 0.1009 -- needs to be qr/^\/$/ (will be fixed in 0.1010)
  55
+  The mapping order matters -- sometimes confusing
12 56
 
  57
+Web::Simple:
  58
+  Can't use regexp for dispatcher rules -- app's responsibility
5  http-router-declare.psgi
@@ -8,7 +8,7 @@ use MyApp::Hello;
8 8
 my $router = router {
9 9
     match '/', { method => 'GET' },
10 10
         to { controller => 'Hello', action => 'index' };
11  
-    match '/blog/{year}/{month}', { method => 'GET' },
  11
+    match '/blog/{year}/{month}', { method => 'GET', year => qr/^\d{4}$/, month => qr/^\d{2}$/ },
12 12
         to { controller => 'Blog', action => 'monthly' };
13 13
     match '/comment', { method => 'POST' },
14 14
         to { controller => 'Blog', action => 'comment' };
@@ -21,7 +21,8 @@ sub {
21 21
 
22 22
     my $p = $match->params;
23 23
     my $controller = "MyApp::" . $p->{controller};
24  
-    my $action = $controller->can(lc($req->method) . "_" . $p->{action});
  24
+    my $action = $controller->can(lc($req->method) . "_" . $p->{action})
  25
+        or return $req->new_response(405)->finalize;
25 26
     my $res = $controller->$action($req, $p);
26 27
     $res->finalize;
27 28
 };
3  httpx-dispatcher.psgi
@@ -19,7 +19,8 @@ sub {
19 19
         or return $req->new_response(404)->finalize;
20 20
 
21 21
     my $controller = "MyApp::$match->{controller}";
22  
-    my $action = $controller->can(lc($req->method) . "_" . $match->{action});
  22
+    my $action = $controller->can(lc($req->method) . "_" . $match->{action})
  23
+        or return $req->new_response(405)->finalize;
23 24
     my $res = $controller->$action($req, $match->{args});
24 25
     $res->finalize;
25 26
 };
2  path-router.psgi
@@ -41,7 +41,7 @@ sub {
41 41
     my $mapping = $match->mapping;
42 42
     my $controller = "MyApp::" . $mapping->{controller};
43 43
     my $action = $controller->can(lc($req->method) . "_" . $mapping->{action})
44  
-        or return $req->new_response(404)->finalize;
  44
+        or return $req->new_response(405)->finalize;
45 45
     my $res = $controller->$action($req, $mapping);
46 46
     $res->finalize;
47 47
 };
9  tester.pl
@@ -26,6 +26,15 @@
26 26
 
27 27
     $res = $cb->(GET "/nonexistent");
28 28
     is $res->code, 404;
  29
+
  30
+ TODO: {
  31
+        local $TODO = "Nice to have";
  32
+        $res = $cb->(POST "/blog/2009/01");
  33
+        is $res->code, 405, '405 on POST requests against GET only endpoints';
  34
+
  35
+        $res = $cb->(GET "/blog/now/today");
  36
+        is $res->code, 404, 'year & month can specify digits';
  37
+    }
29 38
 };
30 39
 
31 40
 done_testing;

0 notes on commit bb19442

Please sign in to comment.
Something went wrong with that request. Please try again.