26. 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
47. SHOW ME THE CODE
CURL
curl -H "Accept: application/hal+json" --request GET
http://drupal-8.localhost/node/1
48. 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);
?>
49. 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"}]}'
50. 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')),
);
51. 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!';
}
?>