dshahin has asked for the wisdom of the Perl Monks concerning the following question:

I need to create a web service to receive XML messages from Google checkout and respond to them in XML. The XML is sent as POST data with various HTTP headers to authenticate. Many of the Perl modules for writing web services seem to be standalone scripts that do their own web serving, but I want to use Apache.

I'm already set up with Apache and SSL, and I'd like to write this service as a CGI script, specifically a CGI::Application.

I need to perform Basic HTTP authentication based on a header and then slurp the XML into something like XML::Simple. Then, based on the data, I need to acknowledge receipt of the message via my own XML message.

Can I do all of this with CGI, or am I missing something?

Any help would be greatly appreciated!

dan shahin

Replies are listed 'Best First'.
Re: CGI and web services
by GrandFather (Saint) on Jan 30, 2007 at 02:13 UTC

    There is something important I don't understand here. You say "receive XML messages from Google checkout", but that sounds to me like client (browser) side unless you work for Google. It may be that you are providing some sort of interface to Google checkout, in which case your application wears two hats - client to Google and server to whomever you are providing the interface to.

    In any case it seems very likely that you can do all of that, but a bare "yes" answer possibly doesn't get you very far. What are your actual sticking points? Have you written any CGI code before?


    DWIM is Perl's answer to Gödel
      Google checkout offers 2 levels of integration. Level 1 involves posting XML shopping carts to their web service and receiving XML validation.

      Level 2 requires writing a web service running on my own server. Google can then pass XML messages to my service to inform my system when various events occur. Thus, I need to write a web service and it must run over ssl.

      I've written many CGI scripts and applications before, but I've never written a "web service". I'm wondering if I can do it from within my familiar CGI::Application framework, or do I need to go with something like SOAP::Lite or Frontier?

      I'm looking for some validation of my approach before I dive headlong into coding

      dan shahin

Re: CGI and web services
by Herkum (Parson) on Jan 30, 2007 at 03:52 UTC

    CGI will allow you to access the HTTP headers, and read input values from a http request. I would say it should be able to do everything that you need it to do.

      How do I access the Raw Post data? It won't be separated into name / value pairs so I'm not sure to access it from a CGI script.

      dan shahin

        Google checkout is going to send you a POST to your CGI script. It has to be a name/value pair. One of those name value pairs is going to contain your XML document.

        This should dump any data that you receive from a POST request. Use this as your script that Google Checkout will call; it will tell you what name/values you are receiving from them.

        #!/usr/bin/perl use CGI; my $q = new CGI; my @names = $q->param(); for my $name (@names) { warn "$name => " . $q->param($name) . "\n"; }

        Note:This data will be sent to the Apache error_log file.