Run a GET query on the /anything endpoint and return the JSON decoded response as an array. The HTTP query is only run when data is accessed. If there's an error an exception is thrown.
Run a GraphQL query and return data as an array. If there's an error an exception is thrown.
$query =<<<'EOD'query Page($uri: [String], $site: [String]) { entry(uri: $uri, site: $site) { id typeHandle status uri title language postDate content}EOD;$variables = ['site'=>1,'uri'=>'/about-us',];$response = $api->query($query, $variables);$data = $api->decode($response);
Build API requests with queries
It can be easier to build a REST API query via a query object.
It is easier to useaqueryobjecttorunAPIrequests. ```phpuseStrata\Data\Query\Query;useStrata\Data\Http\Rest;$api =newRest('https://www.example.com/api/');$api->enableCache();$page =2;$query =Query::uri('posts')->addParam('page', $page)->setCurrentPage($page)->setTotalResults('[meta][total_results]')->setRootPropertyPath('[data]')->setDataProvider($api);
Return a collection of results, along with pagination. Responses are automatically decoded (each item is returned as an array).
You can use a Data Manager to run multiple queries.
useStrata\Data\Query\QueryManager;useStrata\Data\Http\Rest;$manager =newQueryManager();// The first argument is the data provider name$manager->addDataProvider('internal_api',newRest("https://example1.com/api/"));// Add a second data provider$manager->addDataProvider('cms',newRest("https://example2.com/api/"));// Add your first query to run against internal API$manager->add('content',Query::uri('content')->setParam('id',24));// Add a second query to run against CMS API$query =Query::uri('news')->setParam('limit',25);$manager->add('news', $query,'cms');// This runs both queries concurrently and returns data for the content query$data = $manager->get('content');// Return data for the news query$data = $manager->getCollection('news');$pagination = $data->getPagination();