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 strategy and implementation ● There will be ONE lolcat...
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
Drupal and APIs ● 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
The Problem... ● Extremely large dataset, accessible over API ● Data needs to be very current ● Some pages require large amount of API calls
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
Duplicate Data in Drupal ● All Drupal functionality and modules available ● How do you keep data current? ● Can you obtain a list of resources?
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
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
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 of ways
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!
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
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
Conclusion ● APIs are powerful ● APIs are frustrating ● APIs are your friend
Questions? Discussion?
Recommend
More recommend