-
-
Save sachbearbeiter/35ac1ed4261bf586f2df to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/* Script located in the docroot for your Drupal 8 site */ | |
use Drupal\Core\DrupalKernel; | |
use Drupal\Core\Site\Settings; | |
use Symfony\Component\HttpFoundation\Request; | |
$autoloader = require_once __DIR__ . '/core/vendor/autoload.php'; | |
use GuzzleHttp\Client; | |
$client = new Client(); | |
echo '<h1>RESTful request to get a json response for node 1</h1>'; | |
$request = $client->createRequest('GET', 'http://localhost/d8test2/node/1'); | |
// Set the Accept header for the D8 JSON representation | |
$request->setHeader('Accept', 'application/hal+json'); | |
$response = $client->send($request); | |
$json = $response->json(); | |
echo '<pre>' . var_dump($json) . '</pre><hr>'; | |
// Now display just the node body value | |
echo '<h1>Node 1 body value</h1>'; | |
print $json['body'][0]['value']; | |
echo '<h1>Retrieve the complete site</h1>'; | |
$response = $client->get('http://localhost/d8test2/node/1'); | |
$body = $response->getBody(); | |
// By default if the response is large, Guzzle will save the body in a temp file | |
while (!$body->eof()) { | |
echo $body->read(1024); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment