Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Build a Restfull app using drupal

747 views

Published on

Presentation about how to build an API for your drupal CMS

Published in: Internet, Technology, Design
  • Be the first to comment

  • Be the first to like this

Build a Restfull app using drupal

  1. 1. MAY 29 & 30, 2014 Barcelona @alvar0hurtad0 Drupal’s API
  2. 2. SO
  3. 3. SO
  4. 4. SO
  5. 5. SO +18
  6. 6. W
  7. 7. T
  8. 8. Drupal sites Dries Buytaert March 2012
  9. 9. ~7% CMS SITES Dries Buytaert March 2012
  10. 10. 30% WEB SITES Dries Buytaert March 2012
  11. 11. launch top deprecated
  12. 12. T launch top deprecated
  13. 13. T launch top deprecated
  14. 14. T launch top deprecated
  15. 15. 30% WEB SITES Dries Buytaert March 2012
  16. 16. Dries Buytaert March 2012
  17. 17. 7 8
  18. 18. 7 8 IM
  19. 19. 7 8 IM • MULTILINGUAL • UX/ADMINISTRATION EXPERIENCE • MOBILE FRIENDLY • CONFIGURATION MANAGEMENT • WEB SERVICES
  20. 20. Photo: Carlos Francisco Peña
  21. 21. Photo: Carlos Francisco Peña D
  22. 22. Photo: Carlos Francisco Peña D • LAYOUT CLICK BY CLICK • DATA MODEL CLICK BY CLICK • DATABASE QUERYS CLICK BY CLICK • TRIGGERS AND ACTIONS … • USER PERMISSIONS … • WEB SERVICES CLICK BY CLICK
  23. 23. Photo: Carlos Francisco Peña DATA MODEL
  24. 24. Photo: Carlos Francisco Peña DATA MODEL
  25. 25. Photo: Carlos Francisco Peña DATA MODEL
  26. 26. Photo: Carlos Francisco Peña DATA MODEL 
 CONTENT MODELING • CONTENT TYPES • COMMENTS • USER PROFILES • COMMERCE PRODUCTS • ….
  27. 27. DATABASE QUERYS CLICK BY CLICK
  28. 28. DATABASE QUERYS CLICK BY CLICK
  29. 29. DATABASE QUERYS CLICK BY CLICK
  30. 30. DATABASE QUERYS CLICK BY CLICK
  31. 31. DATABASE QUERYS CLICK BY CLICK
  32. 32. USER PERMISSION CLICK BY CLICK
  33. 33. USER PERMISSION CLICK BY CLICK
  34. 34. USER PERMISSION CLICK BY CLICK
  35. 35. USER PERMISSION CLICK BY CLICK
  36. 36. REST SERVICES CLICK BY CLICK
  37. 37. REST SERVICES CLICK BY CLICK
  38. 38. REST SERVICES CLICK BY CLICK
  39. 39. SERVICES AUTHENTICATION
  40. 40. SERVICES AUTHENTICATION IN CORE • HTTP basic authentication • Cookie
  41. 41. SERVICES AUTHENTICATION IN CORE • HTTP basic authentication • Cookie CONTRIBUTED MODULE • Oauth
  42. 42. SHOW ME THE CODE
  43. 43. SHOW ME THE CODE 
 CURL curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1
  44. 44. SHOW ME THE CODE 
 CURL curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1 
 Guzzle <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); // If in a Drupal environment use the HTTP client service. $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $request = $client->get('node/1'); $request->addHeader('Accept', 'application/hal+json'); $response = $request->send()->json(); print_r($response); ?>
  45. 45. SHOW ME THE CODE 
 CURL curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1 
 Guzzle <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); // If in a Drupal environment use the HTTP client service. $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $request = $client->get('node/1'); $request->addHeader('Accept', 'application/hal+json'); $response = $request->send()->json(); print_r($response); ?> 
 CURL curl --include --request POST --user cleverFucker:secret --header 'Content-type: application/hal+json' http:// drupal-8.localhost/entity/node --data-binary '{"_links":{"type":{"href":"http:// drupal-8.localhost/rest/type/node/page"}}, "title": [{"value":"APIdaysBNC"}]}'
  46. 46. SHOW ME THE CODE 
 CURL curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1 
 Guzzle <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); // If in a Drupal environment use the HTTP client service. $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $request = $client->get('node/1'); $request->addHeader('Accept', 'application/hal+json'); $response = $request->send()->json(); print_r($response); ?> 
 CURL curl --include --request POST --user cleverFucker:secret --header 'Content-type: application/hal+json' http:// drupal-8.localhost/entity/node --data-binary '{"_links":{"type":{"href":"http:// drupal-8.localhost/rest/type/node/page"}}, "title": [{"value":"APIdaysBNC"}]}' 
 Guzzle (I) <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $node = array( '_links' => array( 'type' => array( 'href' => 'http://drupal-8.localhost/rest/type/node/page' ) ), 'title' => array(0 => array('value' => 'New node title')), );
  47. 47. SHOW ME THE CODE 
 CURL curl -H "Accept: application/hal+json" --request GET http://drupal-8.localhost/node/1 
 Guzzle <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); // If in a Drupal environment use the HTTP client service. $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $request = $client->get('node/1'); $request->addHeader('Accept', 'application/hal+json'); $response = $request->send()->json(); print_r($response); ?> 
 CURL curl --include --request POST --user cleverFucker:secret --header 'Content-type: application/hal+json' http:// drupal-8.localhost/entity/node --data-binary '{"_links":{"type":{"href":"http:// drupal-8.localhost/rest/type/node/page"}}, "title": [{"value":"APIdaysBNC"}]}' 
 Guzzle (I) <?php use GuzzleHttpClient; $client = new Client('http://drupal-8.localhost'); $client = Drupal::httpClient()->setBaseUrl('http://drupal-8.localhost'); $node = array( '_links' => array( 'type' => array( 'href' => 'http://drupal-8.localhost/rest/type/node/page' ) ), 'title' => array(0 => array('value' => 'New node title')), ); 
 Guzzle (II) $data = json_encode($node); $response = $client->post('entity/node', array( 'Content-type' => 'application/hal+json', ), $data) // Username and password for HTTP Basic Authentication. ->setAuth('klausi', 'secret') ->send(); if ($response->getStatusCode() == 201) { print 'Node creation successful!'; } ?>
  48. 48. SOAP?
  49. 49. SOAP?
  50. 50. SOAP?
  51. 51. QUESTIONS !!! ?¿? !!! I’ve a question
  52. 52. ONE MORE THING
  53. 53. THANKS Alvaro J. HurtadoVillegas www.twitter.com/aspgems www.twitter.com/alvar0hurtad0

×