You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
30 lines
725 B
30 lines
725 B
5 years ago
|
import { BackendSrv } from 'grafana/app/core/services/backend_srv';
|
||
|
|
||
|
export default class HasticAPI {
|
||
|
private url: string;
|
||
|
|
||
|
constructor(instanceSettings: any, private backendSrv: BackendSrv) {
|
||
|
this.url = instanceSettings.url;
|
||
|
}
|
||
|
|
||
|
get(url: string, params?: any) {
|
||
|
return this._query('GET', url, params);
|
||
|
}
|
||
|
|
||
|
private async _query(method: string, url: string, data?: any) {
|
||
|
method = method.toUpperCase();
|
||
|
let options: any = {
|
||
|
method,
|
||
|
url: this.url + url
|
||
|
};
|
||
|
if(method === 'GET' || method === 'DELETE') {
|
||
|
options.params = data;
|
||
|
} else {
|
||
|
options.data = data;
|
||
|
}
|
||
|
|
||
|
const response = await this.backendSrv.datasourceRequest(options);
|
||
|
return response.data;
|
||
|
}
|
||
|
}
|