Transcript
Page 1: Talking to Web Services

Talking to Web ServicesThe outside world from Drupal

Page 2: Talking to Web Services

David BassendineSenior Developer

Me

Day: Mediacurrent

Night: Science & Sustainability

@dbassendine

linkedin.com/in/dbassendine

Page 3: Talking to Web Services

"Web Services"

open data: science, gov. & development

business tools: customers, pm, seo

social: the big conversation

... (very) big data (and growing)

Page 4: Talking to Web Services

compfight.com

Page 5: Talking to Web Services

monitter.com

Page 6: Talking to Web Services

http://goo.gl/bCkJf

Page 7: Talking to Web Services

http://goo.gl/gkuDS

Page 8: Talking to Web Services

agilezen.com

Page 9: Talking to Web Services

campaignmonitor.com image:http://goo.gl/qlQQ8

Page 10: Talking to Web Services

The task ahead ...

Page 11: Talking to Web Services

Creative Commons (CC BY 2.0) by Flickr user mariachily http://goo.gl/iU8aI

Page 12: Talking to Web Services

http://reverb.echo.nasa.gov/

Page 13: Talking to Web Services

agilezen.com

Page 14: Talking to Web Services

Is there a module for that?

Step 0

Page 15: Talking to Web Services

HTTP and REST

Step 1

Page 16: Talking to Web Services

1: HTTP Comm.s

Page 17: Talking to Web Services

1: HTTP Comm.s

Page 18: Talking to Web Services

1: REST architectures

REST SOAP (XMLRPC)

Resources URIs Custom (data packet)

Methods HTTP verbs Custom (data packet)

Errors HTTP codes Custom (data packet)

Data encoding JSON / XML XML

Consistent*, chatty Flexible but inconsistent

REST for your wife: http://tomayko.com/writings/rest-to-my-wife

REST hypermedia: http://martinfowler.com/articles/richardsonMaturityModel.html

REST vs/ SOAP: http://en.wikipedia.org/wiki/Representational_state_transfer

Page 19: Talking to Web Services

API Documentation

Step 2

URLs and path structure

Authentication

Resources

Data formats

Page 20: Talking to Web Services

2: API Documentation

Agile Zen ECHO

URL Structure RESTful RESTful

Authentication Required: Header or Parameter token

Not required for search

Resources Stories, Projects ... Datasets, Granules...

Data formats JSON XML JSON/XML (GET) XML AQL (POST)

dev.agilezen.com http://goo.gl/b38dJ

Page 21: Talking to Web Services

Test in the browser

Step 3

GET test (simple URL) – eg. http://goo.gl/XUFtn

POSTer test (browser plugin) – Chrome: XHR POSTer – Firefox: Poster

Page 22: Talking to Web Services

Plan the approach

Step 4

Page 23: Talking to Web Services

4: Approaches

Drupal core HTTP http://goo.gl/pnML8

REST API Query API drupal.org/project/

rest_api_query

Services Clientdrupal.org/project/

services_client

Feeds (GET only)drupal.org/project/feeds

Page 24: Talking to Web Services

4: Approaches

Page 25: Talking to Web Services

Now start to code ...

Step 5

Page 26: Talking to Web Services

Drupal core HTTP

Drupal 7

Demo: NASA ECHO API

Reason for approach: REST but requires XML

Step 5a

Code: http://drupal.org/sandbox/dbassendine/1829568

Page 27: Talking to Web Services

Drupal core HTTP

Pros

Flexible

Cons

More code (169 lines)

Encoding / decoding not inc.

Less structural consistency

Step 5a

Encoding / decoding not inc.Well structuredrequest/response

Page 28: Talking to Web Services
Page 29: Talking to Web Services

5a: ECHO API

Page 30: Talking to Web Services
Page 31: Talking to Web Services
Page 32: Talking to Web Services
Page 33: Talking to Web Services
Page 34: Talking to Web Services

Demo: ECHO API

Page 35: Talking to Web Services

REST API Query API

Drupal 6 (Open Atrium)

Service: Agile Zen API

Reason for approach: REST and supports JSON

Step 5b

Code: http://drupal.org/sandbox/dbassendine/1828082

Page 36: Talking to Web Services

REST API Query API

Pros

Less code (114L)

Cons

No XML support

Encoding / decoding inc. Assumptions

More structural consistency

Step 5b

Page 37: Talking to Web Services

5b: Agile Zen API

Page 38: Talking to Web Services
Page 39: Talking to Web Services
Page 40: Talking to Web Services
Page 41: Talking to Web Services

Demo: Agile Zen API

Page 42: Talking to Web Services

Creative Commons (CC BY 2.0) by Flickr user Paxson Woelber http://goo.gl/MYPeM

Page 43: Talking to Web Services

Where next?

Rules

Logging

Job Scheduler

Views w/ Data module

Queue

Triggers Internal Export

Core hooks

Page 44: Talking to Web Services

Skills & resources

SimpleXML http://goo.gl/IvaKX (php.net)

HTTP protocol http://www.jmarshall.com/easy/http

REST http://rest.elkstein.org

json_encode/decode http://goo.gl/lKHZ (php.net)

Drupal core HTTP http://goo.gl/pnML8 (d.o)

Drupal REST API Query API drupal.org/project/rest_api_query

Page 45: Talking to Web Services

Top Related