Introduction
There are two techniques to retrieving data with Strata Data: using data providers or queries.
Data providers
Data providers are classes designed to integrate against a type of data provider. They provide the core functionality to send data requests, deal with errors, support for caching and supressing errors for sub-requests, decode response data, and add custom events via the event listener.
You can run any type of request via data providers, so data providers are better for tasks such as saving new data to an API.
Requests look similar to a normal HTTP request:
You can find out more at:
Queries
Query classes provide an object-orientated way to build queries and run them. They use data providers to run the actual requests and use mapping to help parse data from HTTP responses.
Queries are optimised for reading data, so are best used when you want to retrieve data. If you want to save data, then it's best to use a data provider.
Requests look like:
You can find out more at:
Fluent interface
Queries use a fluent interface to make building queries easier. This means methods that set data (and are used for setting up the query) can be chained since they return the current object. This allows you to do things like:
You can also surround the new Query()
statement in brackets to chain everything:
Query manager
Query managers is a wrapper class that can be used to add data providers and run multiple queries at once. It supports running concurrent queries, you can apply cache settings to all queries at once (e.g. cache tags). It provides a simpler way to run multiple queries at once.
Requests look like this:
You can find out more at:
Custom query classes
You can also write your own custom query classes to encapsulate common functionality for your API, making building queries easier.
For example, a fictional NewsQuery
class may set the URI and root property path. Your request will now look like:
You can find out more at:
Last updated