Instantiate a data provider, for example using the generic Http data provider:
use Strata\Data\Http\Http;$api =new Http('https://example.com/api/');
If you need to setup any Seeauthentication
Requests
To make a request use a concrete method from the data provider, these are different for different types of providers. See data providers for documentation.
The generic Http data provider supports request methods such as get(), post() and exists().
Use default HttpClient functionality to return an array of JSON data. Throws a JsonException on invalid JSON data.
getHeader
Return one single header value, or an array of values if there are more than one.
Parameters
$response (ResponseInterface) - Response to extract header from
$header (string) - Header to return (converted to lower case)
Usage
Throwing exceptions on a failed request
By default the API class throws an exception on failed HTTP requests, this is defined as a request that returns the expected HTTP status code (by default 200).
If the status code is in the 4xx range a NotFoundException is thrown, otherwise a FailedRequestException.
Changing expected status code
You can change the expected status code via:
Do not throw exceptions
You can change the default behaviour to throw exceptions and you can check whether a request is successful via isSuccess().
Changing permissions
By default APIs are read-only, this is by design to ensure you don't accidentally write data unwittingly. If you want to write or delete data you need to set this up with you instantiate the API class.
The following permissions exist:
Permissions::READ
Permissions::WRITE
Permissions::DELETE
Example setting permissions to read and write, but not delete: