-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathrequest.ts
More file actions
31 lines (25 loc) · 837 Bytes
/
request.ts
File metadata and controls
31 lines (25 loc) · 837 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import { getBackendSrv } from '@grafana/runtime';
export interface ErrorResponse {
statusCode: number;
message: string;
}
type RequestParamType = {
method: string;
path: string;
baseUrl: string;
data?: { [key: string]: any };
};
const request = async <T = any>({ method, path, baseUrl, data }: RequestParamType) => {
const result = await getBackendSrv().datasourceRequest<T>({
method,
url: `${baseUrl}/base${path}`,
data,
});
return result;
};
export const Get = async <T = any>({ path, baseUrl }: Pick<RequestParamType, 'path' | 'baseUrl'>) => {
return await request<T>({ method: 'GET', path, baseUrl });
};
export const Post = async <T = any>({ path, baseUrl, data }: Pick<RequestParamType, 'path' | 'baseUrl' | 'data'>) => {
return await request<T>({ method: 'POST', path, baseUrl, data });
};