build a restfull app using drupal
DESCRIPTION
Presentation about how to build an API for your drupal CMSTRANSCRIPT
![Page 1: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/1.jpg)
MAY 29 & 30, 2014 Barcelona
@alvar0hurtad0
Drupal’s API
![Page 2: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/2.jpg)
![Page 3: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/3.jpg)
SO
![Page 4: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/4.jpg)
SO
![Page 5: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/5.jpg)
SO
![Page 6: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/6.jpg)
SO +18
![Page 7: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/7.jpg)
![Page 8: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/8.jpg)
W
![Page 9: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/9.jpg)
![Page 10: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/10.jpg)
T
![Page 11: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/11.jpg)
Drupal sites
Dries Buytaert March 2012
![Page 12: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/12.jpg)
~7%
CMS SITES
Dries Buytaert March 2012
![Page 13: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/13.jpg)
30%WEB SITES
Dries Buytaert March 2012
![Page 14: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/14.jpg)
launch
top
deprecated
![Page 15: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/15.jpg)
T
launch
top
deprecated
![Page 16: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/16.jpg)
T
launch
top
deprecated
![Page 17: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/17.jpg)
T
launch
top
deprecated
![Page 18: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/18.jpg)
30%WEB SITES
Dries Buytaert March 2012
![Page 19: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/19.jpg)
Dries Buytaert March 2012
![Page 20: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/20.jpg)
![Page 21: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/21.jpg)
7 8
![Page 22: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/22.jpg)
7 8
IM
![Page 23: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/23.jpg)
7 8
IM
• MULTILINGUAL
• UX/ADMINISTRATION EXPERIENCE
• MOBILE FRIENDLY
• CONFIGURATION MANAGEMENT
• WEB SERVICES
![Page 24: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/24.jpg)
Photo: Carlos Francisco Peña
![Page 25: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/25.jpg)
Photo: Carlos Francisco Peña
D
![Page 26: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/26.jpg)
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
![Page 27: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/27.jpg)
Photo: Carlos Francisco Peña
DATA MODEL
![Page 28: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/28.jpg)
Photo: Carlos Francisco Peña
DATA MODEL
![Page 29: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/29.jpg)
Photo: Carlos Francisco Peña
DATA MODEL
![Page 30: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/30.jpg)
Photo: Carlos Francisco Peña
DATA MODEL
CONTENT MODELING
• CONTENT TYPES
• COMMENTS
• USER PROFILES
• COMMERCE PRODUCTS
• ….
![Page 31: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/31.jpg)
DATABASE QUERYS CLICK BY CLICK
![Page 32: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/32.jpg)
DATABASE QUERYS CLICK BY CLICK
![Page 33: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/33.jpg)
DATABASE QUERYS CLICK BY CLICK
![Page 34: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/34.jpg)
DATABASE QUERYS CLICK BY CLICK
![Page 35: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/35.jpg)
DATABASE QUERYS CLICK BY CLICK
![Page 36: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/36.jpg)
USER PERMISSION CLICK BY CLICK
![Page 37: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/37.jpg)
USER PERMISSION CLICK BY CLICK
![Page 38: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/38.jpg)
USER PERMISSION CLICK BY CLICK
![Page 39: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/39.jpg)
USER PERMISSION CLICK BY CLICK
![Page 40: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/40.jpg)
REST SERVICES CLICK BY CLICK
![Page 41: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/41.jpg)
REST SERVICES CLICK BY CLICK
![Page 42: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/42.jpg)
REST SERVICES CLICK BY CLICK
![Page 43: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/43.jpg)
SERVICES AUTHENTICATION
![Page 44: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/44.jpg)
SERVICES AUTHENTICATION
IN CORE• HTTP basic authentication
• Cookie
![Page 45: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/45.jpg)
SERVICES AUTHENTICATION
IN CORE• HTTP basic authentication
• Cookie
CONTRIBUTED MODULE
• Oauth
![Page 46: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/46.jpg)
SHOW ME THE CODE
![Page 47: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/47.jpg)
SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
![Page 48: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/48.jpg)
SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
Guzzle
<?php
use Guzzle\Http\Client;
$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);
?>
![Page 49: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/49.jpg)
SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
Guzzle
<?php
use Guzzle\Http\Client;
$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"}]}'
![Page 50: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/50.jpg)
SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
Guzzle
<?php
use Guzzle\Http\Client;
$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 Guzzle\Http\Client;
$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')),
);
!
![Page 51: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/51.jpg)
SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
Guzzle
<?php
use Guzzle\Http\Client;
$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 Guzzle\Http\Client;
$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!';
}
?>
![Page 52: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/52.jpg)
SOAP?
![Page 53: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/53.jpg)
SOAP?
![Page 54: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/54.jpg)
SOAP?
![Page 55: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/55.jpg)
QUESTIONS !!! ?¿? !!!
I’ve a question
![Page 56: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/56.jpg)
ONE MORE THING
![Page 57: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/57.jpg)
![Page 58: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/58.jpg)
![Page 59: Build a Restfull app using drupal](https://reader034.vdocument.in/reader034/viewer/2022052618/554bcbc6b4c9058f6c8b470e/html5/thumbnails/59.jpg)
THANKS
Alvaro J. Hurtado Villegas www.twitter.com/aspgems
www.twitter.com/alvar0hurtad0