#mycgiapp.psgi #!/usr/bin/perl use strict; use Plack::Request; use forks::BerkeleyDB; use XML::Simple; use JSON qw(encode_json); use MIME::Base64 qw(encode_base64); use DBI; use SOAP::Lite(); use POSIX qw(ceil); use Data::Dumper; $XML::Simple::PREFERRED_PARSER='XML::Parser'; $SOAP::Constants::DO_NOT_USE_CHARSET = 1; my $app = sub { my $env = shift; my $req = Plack::Request->new($env); my $input=$req->parameters(); my($out)=GetOutput($input); if ($input->{'format'} eq 'json'){ my $json=JSON->new->utf8->encode($out); return [ 200, ['Content-Type' => 'application/json'], [ $json ], ]; } else{ my $xml=XMLout($out,RootName=>"Result",keepRoot=>0,NoAttr=>1, KeyAttr => []); return [ 200, ['Content-Type' => 'text/xml'], [ $xml ], ]; } }; sub GetOutput { #CGI script code # Runs multiple threads/forks to collect data from various apis with SOAP calls return ($headers,$out); } #RAN IT WITH plackup C:\httpd\myapp>plackup -D -r --host 192.168.110.181 --port 5010 --app myapp.psgi Watching ./lib myapp.psgi for file updates. HTTP::Server::PSGI: Accepting connections at http://192.168.110.181:5010/ 10.1.1.4 - - [11/Sep/2014:11:33:57 +0530] "GET /