External APIs and Drupal Strategies for Integrating External API - - PowerPoint PPT Presentation

external apis and drupal
SMART_READER_LITE
LIVE PREVIEW

External APIs and Drupal Strategies for Integrating External API - - PowerPoint PPT Presentation

External APIs and Drupal Strategies for Integrating External API Data Introductions Luke Bainbridge lbainbridge (drupal.org) @midnightLuke (twitter) Topics Drupal and APIs Data APIs The API landscape Caching


slide-1
SLIDE 1

External APIs and Drupal

Strategies for Integrating External API Data

slide-2
SLIDE 2

Introductions

  • Luke Bainbridge
  • lbainbridge (drupal.org)
  • @midnightLuke (twitter)
slide-3
SLIDE 3

Topics

  • Drupal and APIs
  • Data APIs
  • The API landscape
  • Caching strategy and implementation
  • There will be ONE lolcat...
slide-4
SLIDE 4

Data APIs

  • Great way to add relevant information to

your site

  • Can create richer content
  • Can cause painful lag
  • Lack of industry standards can cause

headaches

  • All APIs are different and require different

approaches

slide-5
SLIDE 5
  • Services module can create powerful APIs

○ Services Entity ○ Services Views ○ oAuth ○ Services Token Access

  • Drupal as a consumer

○ Suffers the same issues mentioned before ○ drupal_http_request() is swiss army chainsaw ■ ...or cUrl

Drupal and APIs

slide-6
SLIDE 6

The Problem...

  • Extremely large dataset,

accessible over API

  • Data needs to be very

current

  • Some pages require

large amount of API calls

slide-7
SLIDE 7

The Solutions

Depend on the API

  • Duplicate the data in Drupal
  • Source data on request-by-request basis
  • Build remote entity controller
  • Use vendor widget
  • Link to the external data source
slide-8
SLIDE 8

Duplicate Data in Drupal

  • All Drupal functionality and modules

available

  • How do you keep data current?
  • Can you obtain a list of resources?
slide-9
SLIDE 9

Remote Entity Controller

  • Work is being done to make this a reality!

○ Remote Entity API module

  • Will depend heavily on a flexible API
  • Local fields are possible

○ Wunderkraut’s blog on the subject

slide-10
SLIDE 10

Our Solution

  • Source data during page request
  • Cache responses using drupal’s cache

functionality

  • Provide abstract class for caching to allow

many different API implementations to store responses

  • Use database abstraction conventions
slide-11
SLIDE 11

The Response Cache

  • A successful request is stored in the cache

○ “Successful” is API dependant

  • Cache should be tuned to application and

flushable

  • A cached response may affect the entire

site

  • Responses can be manipulated in a variety
  • f ways
slide-12
SLIDE 12

Why Not the Page Cache?

  • No gain for authenticated traffic
  • No gain for common site-wide API calls
  • Rate-limiting APIs
  • You can still use it later!
slide-13
SLIDE 13

Example: iTunes API

  • Documentation:

○ http://www.apple. com/itunes/affiliates/resources/documentation/it unes-store-web-service-search-api.html

  • Sandbox module

○ https://drupal.org/sandbox/lbainbridge/2152595

slide-14
SLIDE 14

Tips

  • Try to get everything in one request
  • The static cache is your friend

○ drupal_static(__FUNCTION__)

  • Be creative with files

○ Check timestamps ○ Queue updates to files

  • Cache pages as well when possible
slide-15
SLIDE 15

Conclusion

  • APIs are powerful
  • APIs are frustrating
  • APIs are your friend
slide-16
SLIDE 16

Questions? Discussion?