Giter VIP home page Giter VIP logo

plack-dispatching-samples's Introduction

This is a collection of URI dispatching example code using
Plack::Request/Response and various dispatcher modules on CPAN.

Most examples would do:

  GET / => "Hello World" in text/plain
  GET /blog/{year}/{month} => Get the list of blog posts in year/month
  POST /comment => Post a comment with parameters id, name and body

Nice to have:

  /blog/{year}/{month} should be limited to 4-digit year and 2-digit month
  POST to GET-only endpoints should raise 405

You can run tests against the dispatcher using:

  perl tester.pl <dispatcher.psgi>

NOTES

This is NOT a check-no-check comparison. This is NOT a golf contest either.

When it says "Can't do ...", it doesn't necessarily mean a minus - it
means it's application's responsibility, which could mean more
flexibilities.

Also, the requirement "POST to GET-only endpoint should give 405" is
nice to have, while in many cases it's not a fair game to add to
dispatcher, because if the dispatcher supports that, there's no way to
distinguish with non-existent paths (404) and if the dispatcher
DOESN'T support that it becomes app's responsibility which could be
easy.

dancer:
  (Dancer doesn't use Plack::Request -- here's for the comparison)
  Can use named capture and regexp based dispatching
  POST to GET endpoints gives 404 by default

HTTP::Router::Declare:
  Can dispatch using HTTP methods as well
  (You can remove { method => 'GET' } requirement to make 405 fallbacks work)
  Can specify requirement like routes.py

HTTPx::Dispatcher:
  Can't use HTTP method as a dispatcher rule - it's an app's responsibility
  Can't use regular expressions / requirements

Mojolicious::Lite:
  (Mojolicious doesn't use Plack::Request -- here's for the comparison)
  Can use named capture + regexp requirement like Merb / HTTP::Router
  POST to GET endpoints gives 404 by default

Path::Dispatcher:
  Passing PSGI env to the metadata for REQUEST_METHOD matching
  (You can omit that to make 405 fallbacks on the app work)

Path::Router:
  Can use Moose based constraints to validate path chunks
  Can't use HTTP method as a dispatcher rule - it's an app's reponsibility

Tatsumaki:
  Can't use HTTP method as a dispatcher rule - app handlers need to define the verbs
  Default '/' is catch-all as of 0.1009 -- needs to be qr/^\/$/ (will be fixed in 0.1010)
  The mapping order matters -- sometimes confusing

Web::Simple:
  Can't use regexp for dispatcher rules -- app's responsibility

plack-dispatching-samples's People

Contributors

arcanez avatar doy avatar miyagawa avatar sartak avatar tokuhirom avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.