Web services are a treasure trove of tools, content and data. I'll be exploring how we can use Drupal's frameworks to tap into these services. From strategy and selecting the right approach, to triggering, encoding and sending HTTP messages, I'll walk through how you might go about writing a custom integration that puts your Drupal build into a conversation with the outside world. I'll follow up with real world examples I've built to interact with NASA's ECHO Earth science data service (http://earthdata.nasa.gov/echo) and the Agile Zen project management tool (http://agilezen.com).
Sandboxes for the code demoed in this session are available at:
* ECHO - http://drupal.org/sandbox/dbassendine/1829568
* AgileZen - http://drupal.org/sandbox/dbassendine/1828082
Presented by David Bassendine on 10/27/2012 at Drupalcamp Atlanta (https://www.drupalcampatlanta.com/session/talking-web-services).
2. Me
David Bassendine
Senior Developer
Day: Mediacurrent
Night: Science & Sustainability
@dbassendine
linkedin.com/in/dbassendine
3. "Web Services"
open data: science, gov. & development
social: the big conversation
business tools: customers, pm, seo
... (very) big data (and growing)
20. 2: API Documentation
Agile Zen ECHO
URL Structure RESTful RESTful
Authentication Required: Header or Not required for search
Parameter token
Resources Stories, Projects ... Datasets, Granules...
Data formats JSON XML JSON/XML (GET)
XML AQL (POST)
dev.agilezen.com http://goo.gl/b38dJ
21. Step 3
Test in the browser
GET test (simple URL) – eg. http://goo.gl/XUFtn
POSTer test (browser plugin) – Chrome: XHR POSTer
– Firefox: Poster
26. Step 5a
Drupal core HTTP
Drupal 7
Demo: NASA ECHO API
Reason for approach: REST but requires XML
Code: http://drupal.org/sandbox/dbassendine/1829568
27. Step 5a
Drupal core HTTP
Pros Cons
Flexible More code (169 lines)
Well structured Encoding / decoding not inc.
request/response
Less structural consistency
35. Step 5b
REST API Query API
Drupal 6 (Open Atrium)
Service: Agile Zen API
Reason for approach: REST and supports JSON
Code: http://drupal.org/sandbox/dbassendine/1828082
36. Step 5b
REST API Query API
Pros Cons
Less code (114L) No XML support
Encoding / decoding inc. Assumptions
More structural
consistency