I am new to working with an API. I am using guzzle and Laravel. How to I output specific data such as just the actor's name and image?
$client = new \GuzzleHttp\Client();
//$client = new GuzzleHttpClient();
$response = $client->request('GET', '', [
'headers' => [
'x-rapidapi-host' => 'imdb232.p.rapidapi',
'x-rapidapi-key' => 'xxxxxx',
],
]);
echo $response->getBody();
{"data":{"name":{"__typename":"Name","id":"nm0000573","nameText":{"text":"Dolly Parton"}
Here is the data for the image.
"primaryImage":{"__typename":"Image","id":"rm2099682048","url":".V1.jpg",
I am new to working with an API. I am using guzzle and Laravel. How to I output specific data such as just the actor's name and image?
$client = new \GuzzleHttp\Client();
//$client = new GuzzleHttpClient();
$response = $client->request('GET', 'https://imdb232.p.rapidapi/api/actors/get-bio?nm=nm0000573', [
'headers' => [
'x-rapidapi-host' => 'imdb232.p.rapidapi',
'x-rapidapi-key' => 'xxxxxx',
],
]);
echo $response->getBody();
{"data":{"name":{"__typename":"Name","id":"nm0000573","nameText":{"text":"Dolly Parton"}
Here is the data for the image.
"primaryImage":{"__typename":"Image","id":"rm2099682048","url":"https://m.media-amazon/images/M/MV5BMTQxNjI5MjI2NV5BMl5BanBnXkFtZTYwMzExMzI1.V1.jpg",
json_decode
? php/manual/en/function.json-decode.php Should be able to do$obj = json_decode($response->getBody());
, then$obj->data->name->nameText
would output'Dolly Parton'
. That should point you in the right direction