Getting started

Requirements

Installation

Install via Composer:

composer require strata/data:^0.9

Access data from a REST API

Set up your API connection, caching all responses for 1 hour (the default lifetime):

use Strata\Data\Http\Rest;

$api = new Rest('https://httpbin.org/');
$api->enableCache();

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.

$response = $api->get('anything', ['my-name' => 'Thomas Anderson']);
$data = $api->decode($response);

Get the raw response content as a string:

Find out if the API request was successful:

Find out if the API response was cached:

Access data from a GraphQL API

Set up your API connection, caching all responses for 1 hour:

Run a GraphQL query and return data as an array. If there's an error an exception is thrown.

Build API requests with queries

It can be easier to build a REST API query via a query object.

Return a collection of results, along with pagination. Responses are automatically decoded (each item is returned as an array).

Run multiple API requests via the Data Manager

You can use a Data Manager to run multiple queries.

More information

Find out more:

  • TODO

Last updated

Was this helpful?