Menu

Important: This documentation is about an older version. It's relevant only to the release noted, many of the features and functions have been updated or replaced. Please view the current version.

Enterprise Open source

BackendSrv interface

Used to communicate via http(s) to a remote backend such as the Grafana backend, a datasource etc. The BackendSrv is using the Fetch API under the hood to handle all the communication.

The request function can be used to perform a remote call by specifying a BackendSrvRequest. To make the BackendSrv a bit easier to use we have added a couple of shorthand functions that will use default values executing the request.

Signature

typescript
export interface BackendSrv 

Import

typescript
import { BackendSrv } from '@grafana/runtime';

Remarks

By default Grafana will display an error message alert if the remote call fails. If you want to prevent this from happending you need to catch the error thrown by the BackendSrv and set the isHandled = true on the incoming error.

Methods

MethodDescription
datasourceRequest(options)Special function used to communicate with datasources that will emit core events that the Grafana QueryInspector and QueryEditor is listening for to be able to display datasource query information. Can be skipped by adding option.silent when initializing the request.
delete(url)
get(url, params, requestId)
patch(url, data)
post(url, data)
put(url, data)
request(options)

datasourceRequest method

Special function used to communicate with datasources that will emit core events that the Grafana QueryInspector and QueryEditor is listening for to be able to display datasource query information. Can be skipped by adding option.silent when initializing the request.

Signature

typescript
datasourceRequest(options: BackendSrvRequest): Promise<any>;

Parameters

ParameterTypeDescription
optionsBackendSrvRequest

Returns:

Promise<any>

delete method

Signature

typescript
delete(url: string): Promise<any>;

Parameters

ParameterTypeDescription
urlstring

Returns:

Promise<any>

get method

Signature

typescript
get(url: string, params?: any, requestId?: string): Promise<any>;

Parameters

ParameterTypeDescription
urlstring
paramsany
requestIdstring

Returns:

Promise<any>

patch method

Signature

typescript
patch(url: string, data?: any): Promise<any>;

Parameters

ParameterTypeDescription
urlstring
dataany

Returns:

Promise<any>

post method

Signature

typescript
post(url: string, data?: any): Promise<any>;

Parameters

ParameterTypeDescription
urlstring
dataany

Returns:

Promise<any>

put method

Signature

typescript
put(url: string, data?: any): Promise<any>;

Parameters

ParameterTypeDescription
urlstring
dataany

Returns:

Promise<any>

request method

Signature

typescript
request(options: BackendSrvRequest): Promise<any>;

Parameters

ParameterTypeDescription
optionsBackendSrvRequest

Returns:

Promise<any>