From e4d2b6c203d6989ee67c8f1fb3221653b2ba1d45 Mon Sep 17 00:00:00 2001 From: Ryan McKinley Date: Tue, 25 Feb 2020 02:58:05 -0800 Subject: [PATCH] DataSourceWithBackend: Add a get/post resource standard path (#22408) --- .../src/utils/DataSourceWithBackend.ts | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts index 12a180dcf8f..85d57014106 100644 --- a/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts +++ b/packages/grafana-runtime/src/utils/DataSourceWithBackend.ts @@ -80,6 +80,20 @@ export class DataSourceWithBackend< return { data: resultsToDataFrames(rsp) }; } + /** + * Make a GET request to the datasource resource path + */ + async getResource(path: string, params?: any): Promise> { + return getBackendSrv().get(`/api/datasources/${this.id}/resources/${path}`, params); + } + + /** + * Send a POST request to the datasource resource path + */ + async postResource(path: string, body?: any): Promise> { + return getBackendSrv().post(`/api/datasources/${this.id}/resources/${path}`, { ...body }); + } + testDatasource() { // TODO, this will call the backend healthcheck endpoint return Promise.resolve({});