Making a request
Last updated
Was this helpful?
Last updated
Was this helpful?
Instantiate a , for example using the generic Http data provider:
If you need to setup any Seeauthentication
To make a request use a concrete method from the data provider, these are different for different types of providers. See for documentation.
The generic supports request methods such as get()
, post()
and exists()
.
The automatically decodes data as JSON.
The supports request methods such as ping()
and query()
.
an available Data class. RestApi supports things like get and post, GraphQL has a query method. Full details on available methods appear below.
HTTP requests only run once you access data. For example:
At this point the HTTP request is made and if an error occurs an exception is thrown.
You optionally pass a base URI when instantiating the API object. All subsequent API calls are then made relative to the base URI.
Run a GET query.
$uri (string)
API endpoint to query
$queryParams (array)
Array of query params to send with GET request
$options (array)
- Array of options
Please note if you set any query string parameters in $options['query']
these will override any parameters with the same name in $queryParams
.
Get one item. Returns a ResponseInterface
object.
$uri (string)
API endpoint to query
$id (string|int)
Identifier of item to return
Get a list of items. TODO
Run a POST query.
$uri (string)
API endpoint to query
$postData (array)
API endpoint to query
$options (array)
- Array of options
Please note if you set any POST body data in $options['body']
this will override $postData.
Run a HEAD query.
$uri (string)
API endpoint to query
$options (array)
- Array of options
You can run any other type of query via the request
method. Returns a ResponseInterface
object.
$method (string)
- Method to run
$uri (string)
- URI to send request to, relative to base URI
$options (array)
- Array of options
Use default HttpClient functionality to return an array of JSON data. Throws a JsonException
on invalid JSON data.
Return one single header value, or an array of values if there are more than one.
$response (ResponseInterface)
- Response to extract header from
$header (string)
- Header to return (converted to lower case)
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
.
You can change the expected status code via:
You can change the default behaviour to throw exceptions and you can check whether a request is successful via isSuccess()
.
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:
Or via:
See for a full list of options.
Responses are returned as an object of type .