watch this  

the official mrchucho blog

REST vs. SOAP

Posted 2006 Feb 08

I was writing another rbot plugin - this time to get forecast data from the NOAA like my Quicksilver plugin [1] - and I needed a good way to get latitude and longitude. A quick search revealed that the Yahoo Maps API provides just such a thing!

Yahoo’s API is REST based, whereas the NOAA uses SOAP. The differences in complexity are significant. Using REST, I simply create a URL. No special software, no WSDL, no libraries. Not even any particularly deep understanding of the underlying technology is required.
<pre><code>
    def get_lat_long(loc)
        loc = ERB::Util.u(loc)
        url="http://api.local.yahoo.com/MapsService/V1/geocode?appid=YahooDemo&location=#{loc}" 
</code>
That’s it! Now I get back an XML document that I can easily parse with REXML. To do the same thing with SOAP requires a little bit more effort and, to me, doesn’t feel as natural.
<pre><code>
class Forecast
    WSDL_URI="http://www.nws.noaa.gov/forecasts/xml/SOAP_server/ndfdXMLserver.php?wsdl" 
    def initialize(lat,long)
        @lat,@long=lat,long
        @forecaster=SOAP::WSDLDriverFactory.new(WSDL_URI).create_rpc_driver
    end
    def forecast
        forecast = @forecaster.NDFDgenByDay(
            @lat,@long,Time.now.strftime("%Y-%m-%d"),2,"24 hourly")
        xml = (REXML::Document.new(forecast)).root
        File.open("forecast.xml",'w') do |file|
            file < < xml
        end
    end
end
</code>
But, most importantly, you have to use a SOAP client to interact with this service… In the case of Yahoo’s API, I can just type a URL into my browser and get results. This is minor, but can be important when first getting started or when debugging.

1 I’ll post later about the differences in writing this software in Ruby versus Cocoa/Objective-C…

Responses to "REST vs. SOAP"

No responses yet.

Comments are now closed.
atom rss