I need to consume a rest API in my Drupal website and display the data as a table. Can you suggest me to how to do that ? I am new to Drupal so need to know where I need to add the custom code to fetch data and also I went through couple of modules but still did not get the clear picture on how to do it.
Asked
Active
Viewed 1,274 times
2 Answers
1
For Drupal 7 it was drupal_http_request however for Drupal 8, you can use Guzzle for that. You can find more detail with example here

Suman B
- 86
- 1
- 6
0
For consuming REST
GET request
<?php
/**
* @file
* Contains \Drupal\testmodule\Controller\TestController.
*/
namespace Drupal\testmodule\Controller;
use GuzzleHttp\Client;
public function current_contentp(){
$client = new Client();
$json = $client->get('https://catfact.ninja/breeds')->getBody()->getContents();
//..
}

Paul Bradbury
- 482
- 6
- 8