Get JSON data from external website and parse it to show in HTML

Here’s what I used within a custom plugin. It’s the remote class from the Kirby Toolkit (which also uses cURL btw.).

class myClass {
  public static function getJsonData() {
    $tree = [];
    $url = 'http://api.domain.com';

    $request = remote::request($url);
    
    if (!empty($request->content)) {
      $tree = json_decode($request->content);
    }
    return $tree;
  }

And then …

<?php $tree = myClass::getJsonData() ?>
6 Likes