Web Services with
Ruby on Rails : Building Web Service Clients
From a high-level view, web service
implementations can be broken down into two categories: servers and
clients. I'll show how to create both clients and servers
throughout this document. But since you're likely to build more
clients throughout your career, I'll start with clients.
Most web services are based on one of three
architectures: Representational State Transfer (REST), Simple
Object Access Protocol (SOAP), or Extensible Markup Language Remote
Procedural Calls (XML-RPC). Web services often offer access via two
or more of these architectures. For example, we'll be offering both
SOAP and XML-RPC access to clients in the ActionWebService server
examples later in This Site , so clients can implement the
architecture that's easiest for their specific application.
If you're building your web service clients in
Ruby and implementing them as part of a Rails application, you are
in luck. Building web service clients with Ruby on Rails requires
only a few simple steps and involves just a few Ruby libraries.
Even better news is that the majority of libraries you use for
building clientsCGI, NET, REXML, Soap4r, XSD, and XML-RPCare
automatically loaded by your Rails environment. All you have to
worry about is knowing when, how, and where to use each library,
and that's just what I'll help you figure out throughout the rest
of this document.
If you're wondering why I'm talking about Rails
(a server platform) and web service clients in the same breath,
take a step back. Most web service clients aren't desktop programs
or command-line programs. Instead, most web service clients are
servers: servers that gather data from other web services and then
repackage it for some other purpose. (That other purpose is
frequently a human-readable web page, but it could just as well be
yet another web service.) That's why the clients we develop here
will be part of a Rails application.
I'll cover all three of the most popular types
of web services: REST, SOAP, and XML-RPC. And to make things as
practical as possible, I'll use three of the most popular, free,
and useful web services out there for examples: Yahoo! Search,
Google Search, and Flickr. Since I'm a big believer in learning by
doing, I'll walk you through the details of building web service
clients for Rails by developing real-world, working clients for
each of these services.
All this document's examples will focus on
building working clients to demonstrate web services concepts, so I
won't discuss any one service in detail. My goal isn't to teach you
everything you might need to know about a specific web service's
interface, or even everything you might need to know about SOAP or
REST concepts. Rather, my intention is to show you how to apply web
service concepts to your Rails applications. My hope is that you
will then take these examples as starting points and go on to build
the next great client we've all been waiting for! But before I get
too deep into specific examples, I'll cover a few quick basics
about Ruby on Rails and web services.
|