You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
1.3 KiB
TypeScript
59 lines
1.3 KiB
TypeScript
import fetch, {AxiosPromise} from 'axios';
|
|
|
|
import {HTTPMethod, RestCalls} from './restCalls';
|
|
|
|
class DefaultRestCalls implements RestCalls {
|
|
async fetchData(url: string, method: HTTPMethod, headers?: any): Promise<string> {
|
|
const ret = await fetch({
|
|
url,
|
|
method,
|
|
headers,
|
|
transformResponse: (req) => req,
|
|
withCredentials: true,
|
|
timeout: 29000,
|
|
});
|
|
return ret.data;
|
|
}
|
|
|
|
async fetchDataRaw(url: string, method: HTTPMethod, headers?: any): Promise<AxiosPromise> {
|
|
const ret = await fetch({
|
|
url,
|
|
method,
|
|
headers,
|
|
transformResponse: (req) => req,
|
|
withCredentials: true,
|
|
timeout: 29000,
|
|
});
|
|
return ret;
|
|
}
|
|
|
|
async sendData(url: string, method: HTTPMethod, data: string, headers?: any): Promise<string> {
|
|
const ret = await fetch({
|
|
url,
|
|
method,
|
|
data,
|
|
transformResponse: (req) => req,
|
|
headers,
|
|
withCredentials: true,
|
|
timeout: 29000,
|
|
});
|
|
return ret.data;
|
|
}
|
|
|
|
async sendDataRaw(url: string, method: HTTPMethod, data: string, headers?: any): Promise<AxiosPromise> {
|
|
const ret = await fetch({
|
|
url,
|
|
method,
|
|
data,
|
|
transformResponse: (req) => req,
|
|
headers,
|
|
withCredentials: true,
|
|
timeout: 29000,
|
|
});
|
|
return ret;
|
|
}
|
|
|
|
}
|
|
|
|
export const restCalls = new DefaultRestCalls();
|