Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

web::dispatch::httpmethods(3pm) [debian man page]

Web::Dispatch::HTTPMethods(3pm) 			User Contributed Perl Documentation			   Web::Dispatch::HTTPMethods(3pm)

NAME
Web::Dispatch::HTTPMethods - Helpers to make RESTFul Dispatchers Easier SYNOPSIS
package MyApp:WithHTTPMethods; use Web::Simple; use Web::Dispatch::HTTPMethods; sub as_text { [200, ['Content-Type' => 'text/plain'], [$_[0]->{REQUEST_METHOD}, $_[0]->{REQUEST_URI}] ] } sub dispatch_request { sub (/get) { GET { as_text(pop) } }, sub (/get-head) { GET { as_text(pop) } HEAD { [204,[],[]] }, }, sub (/get-post-put) { GET { as_text(pop) } ## NOTE: no commas separating http methods POST { as_text(pop) } PUT { as_text(pop) } }, } DESCRIPTION
Exports the most commonly used HTTP methods as subroutine helps into your Web::Simple based application. Additionally adds an automatic HTTP code 405 "Method Not Allow" if none of the HTTP methods match for a given dispatch and also adds a dispatch rule for "HEAD" if no "HEAD" exists but a "GET" does (in which case the "HEAD" returns the "GET" dispatch with an empty body.) We also add at the end of the chain support for the OPTIONS method (if you do not add one yourself. This defaults to http 200 ok + Allows http headers. Also we try to set correct HTTP headers such as "Allows" as makes sense based on your dispatch chain. The following dispatch chains are basically the same: sub dispatch_request { sub (/get-http-methods) { GET { [200, ['Content-Type' => 'text/plain'], ['Hello World']] } }, sub(/get-classic) { sub (GET) { [200, ['Content-Type' => 'text/plain'], ['Hello World']] }, sub (HEAD) { [200, ['Content-Type' => 'text/plain'], []] }, sub (OPTIONS) { [200, ['Content-Type' => 'text/plain', Allows=>'GET,HEAD,OPTIONS'], []]; }, sub () { [405, ['Content-Type' => 'text/plain', Allows=>'GET,HEAD,OPTIONS'], ['Method Not Allowed']] }, } } The idea here is less boilerplate to distract the reader from the main point of the code and also to encapsulate some best practices. NOTE You currently cannot mix http method style and prototype sub style in the same scope, as in the following example: sub dispatch_request { sub (/get-head) { GET { ... } sub (HEAD) { ... } }, } If you try this our code will notice and issue a "die". If you have a good use case please bring it to the authors. EXPORTS This automatically exports the following subroutines: GET PUT POST HEAD DELETE OPTIONS AUTHOR
See Web::Simple for AUTHOR CONTRIBUTORS
See Web::Simple for CONTRIBUTORS COPYRIGHT
See Web::Simple for COPYRIGHT LICENSE
See Web::Simple for LICENSE perl v5.14.2 2012-05-07 Web::Dispatch::HTTPMethods(3pm)

Check Out this Related Man Page

Web::Simple::Deployment(3pm)				User Contributed Perl Documentation			      Web::Simple::Deployment(3pm)

NAME
Web::Simple::Deployment - various deployment options DESCRIPTION
This file documents common deployment methods for Web::Simple. If you feel one is missing, please ask in the IRC channel and we'll work with you to add it. CGI
The most basic deployment option is as a CGI script loading and running your Web::Simple-module: #!/usr/bin/env perl use Your::Web::Simple::App; Your::Web::Simple::App->run_if_script; Save that as script.cgi and your web server will handle it correctly. Plack-Server This works in with exactly the same code as CGI deployment. However instead of letting your web server load script.cgi, you run this on the command line: plackup script.cgi Self-contained CGI Sometimes your app is so small that you have only one or two tiny classes that you want to run as a CGI script. Web::Simple offers a helpful mechanism to achieve that. #!/usr/bin/env perl use Web::Simple 'HelloWorld'; # enables strictures and warnings for the file # additionally, HelloWorld is upgraded to a # Web::Simple application { package HelloWorld; sub dispatch_request { sub (GET) { [ 200, [ 'Content-type', 'text/plain' ], [ 'Hello world! It is a fine ' . HelloWorld::Helper->day ] ] }, sub () { [ 405, [ 'Content-type', 'text/plain' ], [ 'Method not allowed' ] ] } } } { package HelloWorld::Helper; use DateTime; sub day { return DateTime->now->day_name; } } HelloWorld->run_if_script; AUTHORS
See Web::Simple for authors. COPYRIGHT AND LICENSE
See Web::Simple for the copyright and license. perl v5.14.2 2012-05-07 Web::Simple::Deployment(3pm)
Man Page