> For the complete documentation index, see [llms.txt](https://docs.strata.dev/data/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.strata.dev/data/retrieving-data/data-providers.md).

# Data providers

Data providers are the core means to access external data. These are classes which use custom methods to access data.

Available data providers:

* [Http](/data/retrieving-data/http.md) - generic HTTP data provider
* [Rest](https://github.com/strata/data/blob/main/docs/retrieving-data/rest.md) - data provider for REST-based APIs
* [GraphQL](/data/retrieving-data/data-providers.md) - data provider for GraphQL APOIs

## Common methods

A `DataProvider` interface is used which defines the following common methods for data providers.

### getBaseUri

Return base URI to use for all data requests.

* Returns a string

### getUri

Return URI to use for current data request

* Parameters
  * `string|null $endpoint` Optional endpoint to append to base URI
* Returns a string

### getRequestIdentifier

Return a unique identifier safe to use for caching based on the request

* Parameters
  * `$uri` URI for request
  * `array $context` Array of contextual data (e.g. request options)
* Returns a string

### isSuppressErrors

Whether errors are suppressed

* Returns a boolean

### getDefaultDecoder

Return default decoder to decode responses.

* Returns an object of type `Strata\Data\Decode\DecoderInterface` or null if no default decoder set

### decode

Decode a response

* Parameters
  * `mixed $response` Response to decode (normally an object or array)
  * `DecoderInterface|null $decoder` Optional decoder, if not set uses getDefaultDecoder()
* Returns the decoded data (normally an array or object)

### isCacheEnabled

Is the cache enabled?

* Returns a boolean

### getCache

Return the cache

* Returns an object of type `Strata\Data\Cache\DataCache`

### addListener

Adds an event listener that listens on the specified event. See [events](/data/advanced-usage/events.md).

* Parameters
  * `string $eventName` Event name
  * `callable $listener` The listener
  * `int $priority` The higher this value, the earlier an event listener will be triggered in the chain (defaults to 0)

### addSubscriber

Adds an event subscriber. See [events](/data/advanced-usage/events.md).

* Parameters
  * `EventSubscriberInterface $subscriber` Event subscriber

### dispatchEvent

Dispatches an event to all registered listeners

* Parameters
  * `Event $event` The event to pass to the event handlers/listeners
  * `string $eventName` The name of the event to dispatch
* Returns an object of type `Symfony\Contracts\EventDispatcher\Event`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://docs.strata.dev/data/retrieving-data/data-providers.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
