in reply to Re^2: start over with SOAP in Perl?
in thread start over with SOAP in Perl?

Look at it like this. REST is simple. You need to usually develop your own library to access a REST service, but the REST service is fairly well documented if it is in any way popular. I'd argue PM's XML format to be like that, once you find the docs. :) Anyway, you have to relearn how someone implements rest. Speaking of which, you argue that SOAP is done over HTTP by default. What do you think REST services tend to be written over? :)

I don't view REST as being written "over" anything; rather, it's using HTTP to a fuller extent. For instance, a web service may require user/pass authentication. Many of them do it something like this:

GET /path/to/service?user=foo&pass=bar HTTP/1.1 Host: foobar.com HTTP/1.1 200 OK [other headers] Content-Type: text/plain Error: Username/password invalid

This was acceptable practice back when CGIs were the standard. These days, mod_perl (and equivilents for other languages and servers) let us hook into the server more deeply, including taking over the authentication layer, so we can handle authentication using the headers HTTP already has:

GET /path/to/api?name1=value1&name2=value2 HTTP/1.1 Host: foobar.com Authorization: Basic Zm9v0mJhcg== HTTP 401 Unauthorized [Other headers] [Optional return data]

The advantage here is that you often don't have to write a new library, at least for these common things. LWP::UserAgent (and other WWW libaries) already knows how to do HTTP basic and digest authentication, and its is_success() method should return false for a 401 HTTP response.

The more complex parts of your application will always require code, of course, but letting HTTP handle the things HTTP knows how to handle means that you can focus on the harder bits.

"There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

Replies are listed 'Best First'.
Re^4: start over with SOAP in Perl?
by exussum0 (Vicar) on Aug 30, 2006 at 22:03 UTC
    You have to write a library to parse the response and generate the correct request, not for the underlying HTTP(S) protocol.

    For your example, I have to parse "Error: Username/password invalid" into something, anything. The simplest way to handle this in soap is to throw a fault and do something like $response->get_fault->get_error_message.

      My point was that LWP::UserAgent has already written that code for you, if you design the server end to properly take advantage of what HTTP already has to offer. LWP::UserAgent already knows how to parse '401 Unauthorized'.

      You can still choose to write some additional error handling code, but your overall code will be simpler. More complicated things will need more complicated code, no matter if you use SOAP or REST, so no loss there.

      "There is no shame in being self-taught, only in not trying to learn in the first place." -- Atrus, Myst: The Book of D'ni.

        Not true. You cannot use HTTP error codes for everything. What if you were to use a service where you needed to retieve a record. In SOAP, you don't have to parse the response content manually. It'd be returned back to you as your toolkit provides for you, either as a hash, an object or /something/.

        In REST, i have to put the effort in to take the format and use something on it, whether it's a comma delimited parsing module, an xml parsing module or something custom.

        Look at the perlmonks XML services. If it were in SOAP, I wouldn't need to run an XML parser on them. All of my data would automagically, by the toolkit, be passed back as a hash or set of objects.. or set of arrays. Less to think about.