Perl Web Server Gateway Interface
PSGI: Perl Web Server Gateway Interface | |
---|---|
Basic data
|
|
developer | Tatsuhiko Miyagawa and others |
Current version | 1.102 |
operating system | platform independent |
programming language | Pearl |
category | Middleware |
License | Creative Commons by-sa |
Website |
The Perl Web Server Gateway Interface ( PSGI ) is an interface between web servers and web applications .
Inspired by Python's WSGI and Ruby's Rack , it was developed to promote platform independence for web applications and to simplify their creation. It is a kind of successor to the CGI module, which is no longer included in the core package since Perl 5.22.
PSGI servers are often called PSGI Application Containers based on Java Servlets .
Differences to the CGI
With standard CGI, the data (such as from web forms ) are transmitted from the web server (for example Apache ) via environment variables to the Perl interpreter, which has to start a new process over and over again. With PSGI, each application receives a reference to a hash when it is called (with variables similar to the CGI). The web server itself is either
- your own full Perl web server (like Starman , plackup , etc.),
- a Perl daemon , which is called by a web server (like FastCGI ) or
- a Perl process embedded in the web server (like mod_perl ).
CGI also expects the applications to write HTTP headers and the actual content to STDOUT . PSGI expects an array with three elements from the applications , which also contain the status code.
However, PSGI was deliberately set up similar to CGI in order to enable a switch to and continued use of CGI applications.
use
Many web frameworks use PSGI, such as Catalyst ( BBC iPlayer), Mason / Poet ( Amazon.com , Delicious , Hearst Magazines , DynDNS), Dancer and many more.
example
The following simple example adds the HTTP header field X-Hello-World to each PSGI application (and returns the content Hello World to the client).
# $app ist eine einfache PSGI-Anwendung
my $app = sub {
my $env = shift;
return [ '200',
[ 'Content-Type' => 'text/plain' ],
[ "Hello World" ] ];
};
# $xheader ist ein Stück sogenannte Middleware um $app herum
my $xheader = sub {
my $env = shift;
my $res = $app->($env);
push @{$res->[1]}, 'X-Hello-World' => 1;
return $res;
};
Individual evidence
Web links
- Website (on CPAN, accessed November 2015)
- Johnson, Lee: Documentation for alternative solutions to CGI.pm (on CPAN, accessed November 2015)
- Miyagawa, Tatsuhiko: Lecture (Slides) at the O'Reilly OSCON in July 2010 (English, accessed November 2015)
- PSGI / Plack , Superglue interface between perl web application frameworks and web servers, just like Perl is the duct tape of the internet. (accessed November 2015)