2020-02-26 17:03:53 +08:00
+++
# -----------------------------------------------------------------------
# Do not edit this file. It is automatically generated by API Documenter.
# -----------------------------------------------------------------------
title = "DataSourceWithBackend"
keywords = ["grafana","documentation","sdk","@grafana/runtime"]
type = "docs"
+++
## DataSourceWithBackend class
2020-04-21 16:41:50 +08:00
Extend this class to implement a data source plugin that is depending on the Grafana backend API.
2020-02-26 17:03:53 +08:00
< b > Signature< / b >
```typescript
export declare class DataSourceWithBackend< TQuery extends DataQuery = DataQuery, TOptions extends DataSourceJsonData = DataSourceJsonData > extends DataSourceApi< TQuery , TOptions >
```
< b > Import< / b >
```typescript
import { DataSourceWithBackend } from '@grafana/runtime';
```
< b > Constructors< / b >
2020-10-01 03:45:07 +08:00
| Constructor | Modifiers | Description |
| -------------------------------------------------------------- | --------- | ------------------------------------------------------------------------- |
| [constructor(instanceSettings) ](#constructor-instancesettings ) | | Constructs a new instance of the < code > DataSourceWithBackend</ code > class |
2020-02-26 17:03:53 +08:00
< b > Methods< / b >
2020-10-01 03:45:07 +08:00
| Method | Modifiers | Description |
| --------------------------------------------------------------------------- | --------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| [applyTemplateVariables(query, scopedVars) ](#applytemplatevariables-method ) | | Override to apply template variables. The result is usually also < code > TQuery</ code > , but sometimes this can be used to modify the query structure before sending to the backend.<!-- --> NOTE: if you do modify the structure or use template variables, alerting queries may not work as expected |
| [callHealthCheck() ](#callhealthcheck-method ) | | Run the datasource healthcheck |
| [filterQuery(query) ](#filterquery-method ) | | Override to skip executing a query |
| [getResource(path, params) ](#getresource-method ) | | Make a GET request to the datasource resource path |
| [postResource(path, body) ](#postresource-method ) | | Send a POST request to the datasource resource path |
| [processResponse(res) ](#processresponse-method ) | | Optionally augment the response before returning the results to the |
| [query(request) ](#query-method ) | | Ideally final -- any other implementation may not work as expected |
| [testDatasource() ](#testdatasource-method ) | | Checks the plugin health |
2020-02-26 17:03:53 +08:00
### constructor(instanceSettings)
Constructs a new instance of the `DataSourceWithBackend` class
< b > Signature< / b >
```typescript
constructor(instanceSettings: DataSourceInstanceSettings< TOptions > );
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| ---------------- | ------------------------------------------------------- | ----------- |
| instanceSettings | < code > DataSourceInstanceSettings< TOptions> < / code > | |
2020-02-26 17:03:53 +08:00
2020-04-21 16:41:50 +08:00
### applyTemplateVariables method
2020-07-01 15:12:35 +08:00
Override to apply template variables. The result is usually also `TQuery` <!-- --> , but sometimes this can be used to modify the query structure before sending to the backend.
2020-10-01 03:45:07 +08:00
> **Note:** if you do modify the structure or use template variables, alerting queries may not work as expected
2020-04-21 16:41:50 +08:00
< b > Signature< / b >
```typescript
/** @virtual */
2020-07-01 15:12:35 +08:00
applyTemplateVariables(query: TQuery, scopedVars: ScopedVars): Record< string , any > ;
2020-04-21 16:41:50 +08:00
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| ---------- | ----------------------- | ----------- |
| query | < code > TQuery< / code > | |
| scopedVars | < code > ScopedVars< / code > | |
2020-04-21 16:41:50 +08:00
< b > Returns:< / b >
2020-07-01 15:12:35 +08:00
`Record<string, any>`
2020-04-21 16:41:50 +08:00
### callHealthCheck method
Run the datasource healthcheck
< b > Signature< / b >
```typescript
callHealthCheck(): Promise< HealthCheckResult > ;
```
< b > Returns:< / b >
`Promise<HealthCheckResult>`
2020-07-01 15:12:35 +08:00
### filterQuery method
Override to skip executing a query
< b > Signature< / b >
```typescript
/** @virtual */
filterQuery?(query: TQuery): boolean;
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| --------- | ------------------- | ----------- |
| query | < code > TQuery< / code > | |
2020-07-01 15:12:35 +08:00
< b > Returns:< / b >
`boolean`
2020-04-21 16:41:50 +08:00
### getResource method
Make a GET request to the datasource resource path
< b > Signature< / b >
```typescript
getResource(path: string, params?: any): Promise< any > ;
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| --------- | ------------------- | ----------- |
| path | < code > string< / code > | |
| params | < code > any< / code > | |
2020-04-21 16:41:50 +08:00
< b > Returns:< / b >
`Promise<any>`
### postResource method
Send a POST request to the datasource resource path
< b > Signature< / b >
```typescript
postResource(path: string, body?: any): Promise< any > ;
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| --------- | ------------------- | ----------- |
| path | < code > string< / code > | |
| body | < code > any< / code > | |
2020-04-21 16:41:50 +08:00
< b > Returns:< / b >
`Promise<any>`
2020-07-01 15:12:35 +08:00
### processResponse method
Optionally augment the response before returning the results to the
< b > Signature< / b >
```typescript
processResponse?(res: DataQueryResponse): Promise< DataQueryResponse > ;
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| --------- | ------------------------------ | ----------- |
| res | < code > DataQueryResponse< / code > | |
2020-07-01 15:12:35 +08:00
< b > Returns:< / b >
`Promise<DataQueryResponse>`
2020-02-26 17:03:53 +08:00
### query method
2020-04-21 16:41:50 +08:00
Ideally final -- any other implementation may not work as expected
2020-02-26 17:03:53 +08:00
< b > Signature< / b >
```typescript
2020-07-01 15:12:35 +08:00
query(request: DataQueryRequest< TQuery > ): Observable< DataQueryResponse > ;
2020-02-26 17:03:53 +08:00
```
< b > Parameters< / b >
2020-10-01 03:45:07 +08:00
| Parameter | Type | Description |
| --------- | ------------------------------------------- | ----------- |
| request | < code > DataQueryRequest< TQuery> < / code > | |
2020-02-26 17:03:53 +08:00
< b > Returns:< / b >
`Observable<DataQueryResponse>`
### testDatasource method
2020-04-21 16:41:50 +08:00
Checks the plugin health
2020-02-26 17:03:53 +08:00
< b > Signature< / b >
```typescript
2020-04-21 16:41:50 +08:00
testDatasource(): Promise< any > ;
2020-02-26 17:03:53 +08:00
```
< b > Returns:< / b >
2020-04-21 16:41:50 +08:00
`Promise<any>`
2020-02-26 17:03:53 +08:00