Drupal Web Services - James Trevor - E-Book

Drupal Web Services E-Book

Trevor James

0,0
23,50 €

-100%
Sammeln Sie Punkte in unserem Gutscheinprogramm und kaufen Sie E-Books und Hörbücher mit bis zu 100% Rabatt.

Mehr erfahren.
Beschreibung

In Detail

Drupal is a rich and dynamic open source content management system that can feed content into its framework from other Web applications including Facebook, Flickr, Google, Twitter, and more, using standard communication protocols called web services. You may be aware that content can be driven to your Drupal site from different web applications, but when you think of experimenting with this, you can get bogged down due to limited knowledge of web services. Imagine how you will feel when you catch sight of a book that covers powerful web services that help you to integrate your Drupal site with different web applications

This book covers efficient Drupal web services that help you to speed up your connections to Web applications. It will compel you to learn more and more about web services and use them to easily share data and content resources between different applications and machines. This book also covers the usage of each web service for different purposes. It provides step-by-step instructions on integrating Web services and Web applications with your Drupal powered Web site.

Drupal Web services will show you how to work with all kinds of Web Services and Drupal. The book shows you how to integrate Amazon.com content into your site; add multimedia and video to your site using video services including CDN2 and Kaltura. You will learn how to prevent spam using CAPTCHA, reCAPTCHA and Mollom. You will also learn to explore the different types of Web services Drupal offers and can integrate with using the Services module and XML-RPC. Next you will learn to push content from Google documents, deploying this text and image based content as Drupal nodes.

Next you'll integrate Your site with Twitter, Facebook and LinkedIn and show how to post content from Drupal to these social networking applications automatically. At the end you will be enlightened with authentication methods for integrating Web services with Drupal.

Approach

A practical hands-on guide to integrating Web services with your Drupal Web site. It will start from basic understanding of web services to how your Drupal site can be integrated with web applications using web services.

Who this book is for

If you're are a Drupal user, webmaster, or an administrator who wants to integrate Flickr, Facebook, Twitter, Amazon, LinkedIn, Kaltura and Mollom with your Drupal site then this book will be a good addition to your Drupal library.

You do not need to have programming experience to use this book. Drupal Web Services is written for anyone who works with Drupal on a daily basis.

Sie lesen das E-Book in den Legimi-Apps auf:

Android
iOS
von Legimi
zertifizierten E-Readern

Seitenzahl: 326

Veröffentlichungsjahr: 2010

Bewertungen
0,0
0
0
0
0
0
Mehr Informationen
Mehr Informationen
Legimi prüft nicht, ob Rezensionen von Nutzern stammen, die den betreffenden Titel tatsächlich gekauft oder gelesen/gehört haben. Wir entfernen aber gefälschte Rezensionen.



Table of Contents

Drupal Web Services
Credits
About the author
Acknowledgements
About the reviewers
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Errata
Piracy
Questions
1. About Drupal Web Services
What are web services?
XML and web services
The REST protocol
Standards compliance
Why are web services useful?
Why use web services in Drupal?
How Drupal uses web services
Drupal as a service consumer
Mollom
Auto tagging
Flickr and Flickr API
Apache Solr search integration
Facebook
Drupal as a service provider
Services module
RSS
AMFPHP
XML-RPC
Summary
2. Consuming Web Services in Drupal
Using SOAP
The SOAP message
Enabling SOAP in PHP
Using the SOAP Client module
Installing and configuring the SOAP Client module
Getting started with FedEx Web Services
Using FedEx Shipping Quotes module
Installing and configuring the FedEx Shipping Quotes for Ubercart module
Confirming your Ubercart store settings
Entering your test credentials in the FedEx module configuration
Testing the FedEx Web Service with our Drupal site
SOAP request/call in the FedEx module file
Summary
3. Drupal and Flickr
Accessing Flickr
Your Flickr account
Flickr module
Signing up for a Flickr API key
Configuring the Flickr module
Adding the Flickr filter
Setting Flickr module permissions
Testing the Flickr module
Flickr module blocks
Flickr group photos
Flickr random photo from photoset
Flickr random photos block
Flickr recent photos and recent photosets
Flickr user page photosets, user page random photos, and recent photos
Summary
4. Drupal and Amazon
Accessing Amazon
Signing up for an Amazon Web Services account
Installation and initial configuration of the Amazon module
Testing configuration
Using the Amazon module
Testing the Amazon Example content type
Using the Amazon content type with Views
Using the Amazon filters
Testing the Amazon input filter
Amazon Store module
Using the Amazon Store module
Configuring your Amazon Store
Testing your Amazon Store
Summary
5. Drupal and Multimedia Web Services
CDN2 video
Accessing the CDN2 web service
Signing up for the CDN2 web service
Configuring the CDN2 module
Adding videos using CDN2
Uploading videos with CDN2 content type
Using the Kaltura module and web service
Accessing the Kaltura service
Importing and uploading Kaltura video content
Using the Media: Flickr module
Summary
6. Drupal Web Services the Easy Way: The Services Module
The Services module — what is it?
The Services module – why use it and what does it buy you?
Deployment module
Content distribution
Installing and enabling the Services module
Testing a simple service callback
Creating a Services module and running a custom callback
Creating custom Services module
Adding to our function to allow for returning Photo nodes data
Adding a database query to our custom Services module
Adding arguments
Summary
7. Drupal, Spam, and Web Services
CAPTCHA and reCAPTCHA
Installing and configuring CAPTCHA and reCAPTCHA
Image CAPTCHA
reCAPTCHA
AntiSpam
Installing and configuring AntiSpam
Additional TypePad/AntiSpam module settings
AntiSpam moderation queue
Mollom module
Configuring the Mollom web service
Choosing the content that Mollom will protect
Mollom reports and statistics
Summary
8. Using XML-RPC
XML-RPC and Drupal
Drupal Blog API and Google Docs
Enabling and configuring Blog API
Setting up a Google Documents account
Posting the Google Document to Drupal
Testing and viewing the document on your Drupal site
Removing posts
Syncing content between Drupal sites
Using the Deployment module with Services
The Deployment module
Installing, enabling, and configuring Deployment
Summary
9. Twitter and Drupal
Twitter and Drupal
The Twitter API
The Twitter module
Integrating the Twitter module with Drupal
Registering your website with Twitter
Setting up a Twitter application
Configuring the Twitter module once you have your app setup
Setting up OAuth configuration
Setting up your user account to integrate with Twitter
Posting your Drupal nodes as tweets to your Twitter account
Showing tweets in blocks on your Drupal site
Twitter module page and block Views
Actions and triggers with the Twitter module
Tweet module
Configuring short URLs
Configuring the Tweet module
Summary
10. LinkedIn and Drupal
LinkedIn and Drupal
Installing the LinkedIn Integration and OAuth modules
Using the LinkedIn Integration module
Status update and promoting content to LinkedIn
Setting permissions
Posting LinkedIn profile data to Drupal
Posting Drupal content to LinkedIn
Checking usage statistics for the LinkedIn module
Summary
11. Facebook and Drupal
What is Facebook?
Drupal and Facebook
Requirements for running Drupal for Facebook
Installing and enabling Drupal for Facebook
Installing the Facebook libraries
Setting up Canvas Pages
Creating your first Facebook app
Configuring Drupal to work with your Facebook app
Testing the Facebook application
Editing your Facebook application settings
Summary
12. Authentication Services
OpenID and Drupal
Enabling and configuring the OpenID module
Setting up the OpenID server/provider
OAuth and OAuth Connector
Using OAuth Connector
Configuring a provider connection for Twitter
Setting up the Twitter developer application account
Summary
A. Modules Used in the Book
Modules used in Chapter 1
CCK
Mollom
Auto Tagging
AMFPHP
Modules used in Chapter 2
SOAP Client
FedEx web services
FedEx shipping quotes for Ubercart
Ubercart
Token
Modules used in Chapter 3
Flickr account and API key
Flickr module
idGettr
Modules used in Chapter 4
Amazon web service and API key
Amazon module
Features
Views
Amazon store module
Modules used in Chapter 5
CDN2 web service
CDN2 video module
Kaltura web service
Kaltura module
Media: Flickr
Embedded media field
Modules used in Chapter 6
Services module
Modules used in Chapter 7
CAPTCHA
reCAPTCHA
AntiSpam
Modules used in Chapter 8
BlogAPI module
Google Documents
Deployment module
Modules used in Chapter 9
Twitter module
Tweet
Shorten URLs
Short URL
Modules used in Chapter 10
OAuth module
Autoload
Input Stream
LinkedIn Integration
Modules used in Chapter 11
Drupal for Facebook
Facebook Connect
Facebook Auth
Modules used in Chapter 12
Google Apps authentication
Summary
Index

Drupal Web Services

Drupal Web Services

Copyright © 2010 Packt Publishing

All rights reserved. No part of this book may be reproduced, stored in a retrieval system, or transmitted in any form or by any means, without the prior written permission of the publisher, except in the case of brief quotations embedded in critical articles or reviews.

Every effort has been made in the preparation of this book to ensure the accuracy of the information presented. However, the information contained in this book is sold without warranty, either express or implied. Neither the author, Packt Publishing, nor its dealers or distributors will be held liable for any damages caused or alleged to be caused directly or indirectly by this book.

Packt Publishing has endeavored to provide trademark information about all the companies and products mentioned in this book by the appropriate use of capitals. However, Packt Publishing cannot guarantee the accuracy of this information.

First published: November 2010

Production Reference: 1161110

Published by Packt Publishing Ltd.

32 Lincoln Road,

Olton

Birmingham, B27 6PA, UK.

ISBN 978-1-849510-98-1

www.packtpub.com

Cover Image by Javier Barria ( <[email protected]> )

Credits

Author

Trevor James

Reviewers

John K Murphy

Michael L. Ruoss

Acquisition Editor

Steven Wilding

Development Editors

Akash Johari

Meeta Rajani

Technical Editors

Ajay Shanker

Mohd. Sahil

Copy Editor

Lakshmi Menon

Indexers

Hemangini Bari

Monica Ajmera Mehta

Rekha Nair

Editorial Team Leader

Aanchal Kumar

Project Team Leader

Lata Basantani

Project Coordinator

Zainab Bagasrawala

Proofreaders

Aaron Nash

Denise Dresner

Graphics

Nilesh Mohite

Production Coordinator

Kruthika Bangera

Cover Work

Kruthika Bangera

About the author

Trevor James is a Drupal consultant and web developer based in Middletown, MD, USA. Trevor has been designing websites for 14 years using a combination of HTML, XHTML, CSS, and ColdFusion, and has been using Drupal intensively for over 3 years. Trevor’s focus is on building web portals for higher education, public education (K-12), non-profit, medical systems, and small business environments.

He is interested in best methods of integrating web services with Drupal sites, Drupal site performance, and using CCK, Views, and Panels to develop frontend interfaces to support data intensive websites. He loves teaching people about Drupal and and also about how to use this excellent open source content management framework.

Trevor has designed and developed websites for non-profit, education, medical-based systems, and small business organizations. He is currently working on a number of Drupal-related projects.

Trevor co-authored the Packt title Drupal 6 Performance Tips, published in February, 2010. For more on this title visit:

https://www.packtpub.com/drupal-6-performance-tips-to-maximize-and-optimize-your-framework/book

Trevor created an 11+ hour video tutorial series titled Introduction to Drupal 6 for VTC (Virtual Training Company) in 2009. The video is available via the VTC website at:

http://www.vtc.com/products/Introduction-To-Drupal-6-Tutorials.htm

Acknowledgements

Without the love and support of my wife Veronica and our twin daughters Clare and Francesca, this book would not have seen the light of day. I cannot express enough love and grace to the three of you for your encouragement and enthusiasm for my writing career.

Thanks (again!) to my father-in-law Tony Gornik for offering his residence in Hershey, PA as writing space on weekends.

Many thanks to the entire Packt editorial, project, marketing, and production teams for inviting me to work on this project and for continuing to publish exceptional titles on Drupal and open source applications. Many thanks to Steven Wilding, Packt Acquisition Editor, for serving as the lead editor on this title. Steven’s encouragement and wisdom kept me on task with this book.

Thanks to Zainab Bagasrawala, Project Coordinator; Poorvi Nair, Project Coordinator; Akash Johari, Development Editor; Meeta Rajani, Development Editor; Lata Basantani, Projects Team Leader; Mohd Sahil, Technical Editor; and Patricia Weir, for keeping the project on track and for guiding the construction of this title.

A special thanks to Radha Iyer, Marketing Research Executive at Packt. I’ve worked closely with Radha on all aspects of marketing my first book, as well as having the opportunity to write multiple book reviews for Packt under Radha’s guidance and vision. I am always impressed with Radha’s ability to locate new marketing opportunities and applications to help increase knowledge about Drupal and open source.

Thank you to Jim Mason and Eric Condren for their help and knowledge using Drupal and CiviCRM at Frederick County Public Schools on multiple projects.

Susan Morrison and Ryan Wexler of Medical Business Systems were instrumental in testing and implementing many of the social application service integrations documented in this book. While writing the book, I worked closely with them on a redesign of the MBS website and integrated Twitter, Facebook, and LinkedIn with their new site. They taught me a great deal about these integrations from the end user and website manager perspectives.

Last but certainly not least, thanks to my friend and colleague Will McGrouther. Will is an expert on social web applications and the many discussions we had over the course of this book’s roadmap inspired the text in many ways.

I look forward to working with you all in the near future. Drupal on!

About the reviewers

John K Murphy is a software industry veteran with more than 25 years experience as a programmer and database administrator. A graduate of the University of West Virginia, he began writing computer games in the 1980s before pursuing a career as a computer consultant. Over the years, John has enjoyed developing software in most major programming languages while striving to keep current with new technologies.

In his spare time, John enjoys scuba diving, skydiving, and piloting small planes. He lives with his wife and two children in Pittsburgh, Pennsylvania.

Michael Ruoss is founder of and senior developer at UFirst Group. He holds a Master’s Degree in Computer Science from Swiss Federal Institute of Technology in Zurich. After his studies, he worked for Optaros for two years as a developer/consultant. In 2010, he founded UFirst Group, a company doing system integrations based on open source frameworks.

During the past years, working for Optaros and UFirst Group, Michael Ruoss gained much experience in the integration of Drupal, Magento, Alfresco, and other CMS and eCommerce solutions. Michael also maintains two Drupal community modules, the SEO Compliance Checker, and the Overlay Gallery.

The book is dedicated to my wife Veronica and our daughters Clare and Francesca.

Preface

Drupal is a rich and dynamic open source content management system that can feed content into its framework from other web applications including Facebook, Flickr, Google, Twitter, and more, using standard communication protocols called web services. You may be aware that content can be driven to your Drupal site from different web applications, but when you think of experimenting with this, you can get bogged down due to limited knowledge of web services.

This book offers a practical hands-on guide to integrating web services with your Drupal website. It will compel you to learn more and more about web services and use them to easily share data and content resources between different applications and machines. This book also covers the usage of each web service for different purposes. It provides step-by-step instructions on integrating web services and web applications with your Drupal-powered website.

Drupal Web Services will show you how to work with all kinds of web services and Drupal. The book shows you how to integrate Flickr.com and Amazon.com content into your site; add multimedia and video to your site using video services including CDN2 and Kaltura. You will learn how to prevent spam using CAPTCHA, reCAPTCHA, and Mollom. You will also learn to explore the different types of web services Drupal offers and can integrate with using the Services module and XML-RPC. Next, you will learn to push content from Google documents, deploying this text and image-based content as Drupal nodes.

Next, you'll integrate your site with Twitter, Facebook, and LinkedIn and show how to post content from Drupal to these social networking applications automatically. At the end, you will learn about authentication methods for integrating web services with Drupal.

What this book covers

Chapter 1, About Drupal Web Services, focuses on web services from an introductory standpoint and defines what web services are and how they work with Drupal 6.

Chapter 2, Consuming Web Services in Drupal, turns to a discussion of how our Drupal site can act as a web services consumer. We discuss and show examples of using SOAP. We also install, configure, and use the FedEx Shipping Quotes module to get real-time shipping quotes in our Ubercart site.

Chapter 3, Drupal and Flickr, focuses on installing and configuring the Flickr module to communicate with the Flickr web service and display dynamic Flickr photo galleries on our Drupal site.

Chapter 4, Drupal and Amazon, focuses on installing and configuring both the Amazon and the Amazon Store modules to communicate with our Amazon associate account and practice filtering in specific Amazon products including books, CDs, DVDs, and other items into our Drupal nodes.

Chapter 5, Drupal and Multimedia Web Services, focuses on other types of multimedia including video and how we can integrate our Drupal site with two popular video hosting services, CDN2, and Kaltura.

Chapter 6, Drupal Web Services the Easy Way: The Services Module, focuses on installing and enabling the Services module and explore what the Services module offers our Drupal site(s).

Chapter 7, Drupal Spam and Web Services, focuses on installing and using various modules including CAPTCHA, reCAPTCHA, and Mollom to integrate our Drupal website with spam prevention web services.

Chapter 8, Using XML-RPC, looks in more detail at how Drupal uses the XML-RPC protocol and how this protocol can help integrate your Drupal site with external web service-based applications and servers. We'll deploy content from a Google Documents account to our Drupal site.

Chapter 9, Twitter and Drupal, focuses on installing and enabling a few Twitter-based modules to allow for integration with the Twitter web service API.

Chapter 10, LinkedIn and Drupal, focuses on exploring methods of integrating the popular professional social networking application LinkedIn with our Drupal site.

Chapter 11, Facebook and Drupal, focuses on exploring methods of integrating Drupal with the popular social networking web application Facebook.

Chapter 12, Authentication Services, focuses on exploring methods various web service authentication methods and protocols for use with your Drupal site including OpenID and OAuth.

Appendix A, Modules used in the Book, summarizes the contributed modules we've used in the book and present a listing of modules that allow for integration between Drupal and web service applications and servers.

What you need for this book

The book assumes you have a working installation of Drupal 6.19 (latest Drupal 6 version at time of this book's release). If you need to install Drupal, you can do this by first setting up a localhost development environment on your computer. First, you will need to install a LAMP stack on your computer (Apache web server, MySQL, and PHP. You will also need to install the latest version of Drupal 6. Drupal can be downloaded at: http://drupal.org/.

For an easy to install Drupal package that includes the entire suite of Apache, MySQL, and PHP, you can download the Acquia Stack Installer. This will install the entire LAMP and Drupal application stack on your computer. The Acquia Stack Installer can be downloaded at: http://acquia.com/downloads.

The book installs and runs Drupal on a Windows PC but you can easily run the Acquia Stack Installer on a Mac or Linux computer.

For detailed instructions on installing the Acquia Stack go to: http://acquia.com/documentation/acquia-drupal-stack.

Who this book is for

If you are a Drupal user, webmaster, or Drupal site administrator who wants to integrate Flickr, Facebook, Twitter, Amazon, LinkedIn, Kaltura, and Mollom with your Drupal site then this book will be a good addition to your Drupal library.

You do not need to have programming experience to use this book. Drupal web services is written for anyone who works with Drupal on a daily basis.

Conventions

In this book, you will find a number of styles of text that distinguish between different kinds of information. Here are some examples of these styles, and an explanation of their meaning.

Code words in text are shown as follows: "We can include other contexts through the use of the include directive."

A block of code is set as follows:

<?xml version="1.0"?> <methodCall> <methodName>examples.getBlogName</methodName> <params>

New terms and important words are shown in bold. Words that you see on the screen, in menus or dialog boxes for example, appear in the text like this: "clicking the Next button moves you to the next screen".

Note

Warnings or important notes appear in a box like this.

Tip

Tips and tricks appear like this.

Reader feedback

Feedback from our readers is always welcome. Let us know what you think about this book – what you liked or may have disliked. Reader feedback is important for us to develop titles that you really get the most out of.

To send us general feedback, simply send an e-mail to <[email protected]>, and mention the book title via the subject of your message.

If there is a book that you need and would like to see us publish, please send us a note in the SUGGEST A TITLE form on www.packtpub.com or e-mail <[email protected]>.

If there is a topic that you have expertise in and you are interested in either writing or contributing to a book on, see our author guide on www.packtpub.com/authors.

Customer support

Now that you are the proud owner of a Packt book, we have a number of things to help you to get the most from your purchase.

Tip

Downloading the example code for this book

You can download the example code files for all Packt books you have purchased from your account at http://www.PacktPub.com. If you purchased this book elsewhere, you can visit http://www.PacktPub.com/support and register to have the files e-mailed directly to you.

Errata

Although we have taken every care to ensure the accuracy of our content, mistakes do happen. If you find a mistake in one of our books – maybe a mistake in the text or the code – we would be grateful if you would report this to us. By doing so, you can save other readers from frustration and help us improve subsequent versions of this book. If you find any errata, please report them by visiting http://www.packtpub.com/support, selecting your book, clicking on the let us know link, and entering the details of your errata. Once your errata are verified, your submission will be accepted and the errata will be uploaded on our website, or added to any list of existing errata, under the Errata section of that title. Any existing errata can be viewed by selecting your title from http://www.packtpub.com/support.

Piracy

Piracy of copyright material on the Internet is an ongoing problem across all media. At Packt, we take the protection of our copyright and licenses very seriously. If you come across any illegal copies of our works, in any form, on the Internet, please provide us with the location address or website name immediately so that we can pursue a remedy.

Please contact us at <[email protected]> with a link to the suspected pirated material.

We appreciate your help in protecting our authors, and our ability to bring you valuable content.

Questions

You can contact us at <[email protected]> if you are having a problem with any aspect of the book, and we will do our best to address it.

Chapter 1. About Drupal Web Services

Besides its core content management functionality, Drupal can also feed content into its framework from other web applications, including Flickr, Twitter, Google, Amazon, Facebook, Mollom, and many more. This communication between Drupal and other web portals is what makes Drupal a feature-rich content management framework capable of supporting multiple methods of feeding content into its database and site structure. For example, as a Drupal developer, you can feed content into your Drupal site using aggregation or RSS feeds. The Drupal FeedAPI (Application Programming Interface) module allows you to take RSS or XML URLs from external websites and add these feeds to your Drupal site. This is one robust method of getting content from other web applications and sites.

How do we take content from all of these different web applications and share the content with a Drupal site? This is becoming highly important now due to the wealth of rich content management applications that are both on the market and also available in the open source community. For example, how can we take all of the images we upload to our Flickr site and share those images with users on our Drupal site? In this book, we'll look in detail at the Drupal Services module, a contributed module that helps you to speed up your connections to web services. This module will allow us to integrate your Drupal site with external applications by using interfaces, such as XMLRPC, JSON, JSON-RPC, REST, SOAP, and AMF. These interfaces will allow your Drupal site to interact with and provide web services.

In this chapter, you will learn the basics of web services and Drupal, including:

What are web services and why are web services useful?Why do we use web services in Drupal?How does Drupal 6 use web services?Standards compliance when using web services in DrupalDrupal as a service consumer and as a service provider

Let's begin our discussion of what web services are and how they work with Drupal. To get started, we need to define some of the larger concepts and the Drupal concepts that we'll be talking about.

What are web services?

In order for our Drupal site to communicate and interact with other web applications, such as Flickr, Amazon, Mollom, or Twitter, we need to use standard communication protocols in the web development world called web services. Web service protocols will allow applications that reside on external websites and servers to interact and communicate with our Drupal website that is running on our own server. Web services will also allow our Drupal site to pass along content and data to external web applications existing on remote servers.

When we define web services, we need to point out that this type of communication provides for interoperability. This means that a web service communication can happen between two completely different environments but still work because we use standard protocols to make it happen.

Web services allow us to call another application on a remote server. A good analogy to this is using your cell phone to call a friend or colleague. You have one type of cell phone using one type of cell phone service. You call your colleague's cell phone. They have another type of cell with a different service provider, but the call goes through and is successful because the two services communicate with each other using standard cell phone communication protocols.

The web service call happens through coded protocols that are translated into a language and standard protocol that both computers can understand. Generally, this is done by using the XML language to translate the programmed request into the other external applications. Web applications have a standard in which they can usually read XML files. XML is a text-based format, so nearly all computer systems and applications can work with the XML format.

The web services protocol also uses a concept called remoting or Remote Procedure Calling (RPC) that allows one application to initiate or "call" a function inside of an application on a remote server. Our Drupal site can communicate with an application on a remote server and call a function in that application. For example, we might want to make our Drupal website call and interact with our Flickr photo gallery, or we may want to take all of our Drupal home page content and push it over to our Facebook account. We can do both of these actions using the web service protocols.

The computer that contains the application – that we will communicate with – can be anywhere in the world. It could be sitting on a server in the US, Europe, Asia, South America, or somewhere else.

XML and web services

As mentioned above, the base foundation for web services is a protocol or code called XML. For our Drupal site residing on our server, to talk and interact with a website or application on another server, we need to use XML, which is a language commonly understood between different applications. Our site and server understands XML as does the application we want to communicate with. We can do this over the standard http protocol for website communication, as http is the most standard protocol for Internet communication. The reason we use XML for communication between the applications and the sites is because XML replaces the proprietary function (whether the function is in RPC or another programming language or interface) and formats it into the standard XML code format. This allows applications to understand each other easily.

An analogy to this is: if we have two people, one from Germany and the other from France, speaking to one another, and neither person knows the other's language but both of them know English, then they must speak in English, as it's a language they both understand and can easily communicate in. It's a similar situation when XML is used to translate a web service's function into a commonly understood format.

So first we need to send the function call to a remote application. Our calling application or website creates the XML document that will represent the programmed function we want to execute. The XML is then transmitted over HTTP to the remote application and it can then be interpreted and understood by the remote application. The remote application then executes the function based on the XML formatting.

Some examples of web service's methods are SOAP (Simple Object Access Protocol), UDDI (Universal Description, Discovery and Integration), WSDL (Web Services Description Language), XML-RPC (XML Remote Procedure Call), JSON (JavaScript Object Notation), JSON-RPC, REST (Representational State Transfer), and AMF (Action Message Format). We are not going to look at these interfaces in detail now but we will explore how they work with Drupal later in this book when we take a more detailed look at how the Services module works. For now, it's helpful for us to understand that these protocols and platforms exist and that our Drupal site can provide web services to other applications via these multiple interfaces and platforms.

Here's a diagram that outlines a simple web service request and response. This is a request sent from our Drupal site (client) over http to an external server to request data. The data exists on the server (remote) in the form of a URI (Uniform Resource Identifier) item. The response is sent back to our Drupal site through XML.

The REST protocol

Let's look briefly at one web service protocol and technology, and define it. As mentioned before, there are many technologies you can use to implement web services. REST (Representational State Transfer) is one such technology. The reason REST is a preferred technology within the web development and Drupal community is due to its flexibility and standards. REST allows us to do the following when we initiate a web service using its protocol:

Use a standard method such as XML as our message formatSend the message over standard protocol such as HTTPProvide or connect to specific resources where each resource (image, document, page, and node) is given a unique resource identifier (a URI)

We can take this concept and try it out on our Drupal site by writing some PHP code that makes an HTTP request to another web application resource. For example, we may want to make a call to a Picasa photo gallery and feed a select number and type of photos back to our Drupal site and display the photos in a Drupal node on our site. The request targets this specific resource by making a GET request to the URI of the resource. The application we are communicating with sends a response back to us in XML format. That XML can then be integrated into our Drupal site using a module, for example. The request might be made to a user's Flickr or Picasa photo gallery. The request gets returned to our Drupal site as XML and we parse this XML into our Drupal site and the user's photos or gallery then get displayed on our site.

This is just one protocol example. We'll discuss in detail about the other protocols in the later chapters.

Note

Greg Hines of pingVision provides a good introductory resource on REST and Drupal in the document titled RESTful Web Services and Drupal. The document is available on pingVision's website as a PDF download from: http://pingvision.com/files/restful_web_services_and_drupal.pdf

Standards compliance

As discussed in the REST protocol's example, web services and Drupal's use of web services follow specific standards. In order to maintain as much interoperability and flexibility as possible, all of the protocols used respond for the most part using XML as the standard response mechanism and format.

Additionally, all the communication between services, in our example between a client and a server, happens over HTTP (the standard web protocol). This is a uniform protocol that is used for transport and communication of the service. All transports take place uniformly using GET, POST, PUT, and DELETE requests, for example.

The HTTP requests are stateless, meaning that the request over HTTP happens once at one given moment and is isolated from all other activated requests. So the request stands alone. If it succeeds, it gets a response. If it fails, it gets no response from the server or application it's communicating with. The request can be repeated an infinite number of times.

Finally, all of the resources we try and access are those that we are sending to another application using a unique resource identifier (URI) to identify and define what they are. So images on our site have unique identifiers as well as those residing in another web application. Each of these unique identifiers allows for addresses or locations for each node or file in question. So each resource in a web service's communication has an address. Each resource has one URI and each address has one URI. Some examples of this would be the following locations on my Drupal site:

http://variantcube.com/http://variantcube.com/recommended-drupal-resourceshttp://variantcube.com/node/68http://variantcube.com/search/node/podcasthttp://variantcube.com/rss.xml

Another reason we want to be standards compliant, when writing or working with web services, is for simplicity. We do not need any special tools to program web services as long as we follow these standards. We can use the web application modules and PHP, and stick to these coding standards and protocols.

Why are web services useful?

Web services are useful for a number of reasons, especially when it comes to Drupal and Drupal's relationship and interaction with other web content management systems and applications. The web has a huge number of web applications, so web developers and content developers can pass their content to the web browsers and make it available to the web visitors. This is why the Internet is useful to us. We can go to a website and view the content. Whenever we do that, we're looking at content that is proprietary to a specific web application. In Drupal, our content is in the form of nodes, for example. We may want to share these nodes with other websites that are non-Drupal, such as a Wordpress-powered site.

Web services are useful because they present us with an architecture where a resource on a site (an image, textual content, such as a node ID or block ID, a video or audio file) is given a unique identifier. For example, in Drupal, every node has an ID. Every file you upload to a Drupal site also has a unique path to it.

This is extremely useful since all applications share this common semantic standard. We name things similarly on all of our web applications. We can then leverage this by writing code in PHP, for example, the one that calls these resources. The application server that houses the resource then responds to our request using an XML document.

Why use web services in Drupal?

With web services, we can take our Drupal content and share this content with other web applications and, essentially, with the web at large. Our content is no longer just our content and it is not specific to our Drupal website. It can be shared and integrated. Drupal's codebase is PHP-based and many of the popular web applications being used today, including Wordpress, Joomla!, and Flickr, are also PHP-based. So we have a common programming language we can work with and use to integrate these applications.

Here are some concrete examples. Perhaps your Human Resources Department wants to integrate its job postings and applications with another web application such as Monster.com. Web services can allow this to happen. Your office's payroll department may want to connect to its bank account in order to pass data from the payroll reports over to its bank reporting mechanism. Web services can allow this to happen. You may want to take all of the photos you upload to your Drupal site in image galleries built with the Views module, and take these photos and send them to Flickr so that they automatically show up in your Flickr account or on Flickr's public site. Web services can make this happen.

This leads to another advantage of using web services with Drupal and why we would choose to use Drupal in the first place. Instead of having to upload our photos twice – once to our Drupal site and then repeating the procedure to our Flickr site – web services allows us to upload the images to our Drupal site once and then automatically send that data over to Flickr without having to upload one (or even a batch of images) again. It saves us time and speeds up the entire process of generating web-based content.

Additionally, there may be applications we want to use in our Drupal site, for example applications where we want to consume content without having to code again. We can just reuse these applications using the web services protocols and get this application content into our Drupal site. So we can consume web services. Examples of this would be converting currency on our site, feeding weather reports and other weather data into our site, feeding natural disaster scientific data into our site from services that provide it, feeding language translation services, feeding music podcasts, and more. Instead of having to reprogram this type of content, we can grab it from another web application and show it automatically on our site using web services.

Simply put, this opens up a method of easily sharing data and content resources between applications and machines that are running on different platforms and architecture. We have opened up a gold mine of capabilities here because we can talk to applications that run different software from our Drupal site and on different computing platforms.

How Drupal uses web services

Drupal can use web services following any of the protocols mentioned earlier, including XML-RPC, REST, and SOAP. Drupal can consume web services by requesting data from other web applications using RSS and XML-formatted requests. As a web developer, you can write your own service code in Drupal using PHP. You can also use the Services module as well as other service-specific contributed modules to create these web service requests. In this next section, we're going to look at both these examples. First, we'll see how Drupal works as a service consumer, where basically it is a client requesting data from an external server.

We'll also look at how Drupal can provide services using the Services module, RSS, AMFPHP, and XML-RPC. All of these protocols will be explained in detail in the later chapters.

Drupal as a service consumer

Let's outline some brief examples of how Drupal consumes content and data from other web applications, including Mollom, Flickr, and Facebook. We're going to look at these applications in more detail later in the book, but we'll introduce them here and show some basic examples.

You can configure your Drupal site to consume various web services by using contributed Drupal modules for each specific task or application you are trying to consume. Drupal can consume services from applications that will help your website prevent spam, integrate photos, integrate taxonomy and tags, and enhance your Drupal free tagging and autotagging abilities, and integrate with applications such as Facebook and Twitter.

Mollom

Mollom is a web service that will help you to block spam on your Drupal site. It's a separate application that runs as a web service. Drupal can connect to the Mollom web service through a contributed module called Mollom. The contributed module project page is available at http://drupal.org/project/mollom