axios#AxiosBasicCredentials TypeScript Examples
The following examples show how to use
axios#AxiosBasicCredentials.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async get<T>(uri: string, queryParams?: {[key: string]: any}): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
// `${this.config?.rootURL}${uri}
const resp: AxiosResponse = await axios.get(url, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
if (resp.data.isError) reject(resp.data.value);
resolve(resp.data.value as T);
});
}
Example #2
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async getRaw<T>(uri: string, queryParams?: {[key: string]: any}): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
// `${this.config?.rootURL}${uri}
const resp: AxiosResponse = await axios.get(url, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data);
resolve(resp.data as T);
});
}
Example #3
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
// getNoData will return true if the response code falls between 200-299
private async getNoData(uri: string, queryParams?: {[key: string]: any}): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
// `${this.config?.rootURL}${uri}
const resp: AxiosResponse = await axios.get(url, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
if (resp.data.isError) reject(resp.data.value);
resolve(true);
});
}
Example #4
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async delete(uri: string, queryParams?: {[key: string]: any}): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.delete(url, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(true);
});
}
Example #5
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async deleteWithResponse(uri: string, queryParams?: {[key: string]: any}): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.delete(url, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(resp.data.value);
});
}
Example #6
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async post<T>(uri: string, data: any, queryParams?: {[key: string]: any}): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.post(url, data, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error.error);
if (resp.data.isError) reject(resp.data.value);
resolve(resp.data.value as T);
});
}
Example #7
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async postRawReturn<T>(uri: string, data: any, queryParams?: {[key: string]: any}): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.post(url, data, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(resp.data as T);
});
}
Example #8
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async postNoData(uri: string, data: any, queryParams?: {[key: string]: any}): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.post(url, data, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(true);
});
}
Example #9
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async postNoPayload(uri: string): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
const resp: AxiosResponse = await axios.post(buildURL(this.config?.rootURL!, {path: uri}), {}, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(true);
});
}
Example #10
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async postFile(uri: string, inputName: string, file: File): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*', 'Content-Type': 'multipart/form-data'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
const formData = new FormData();
formData.append(inputName, file);
const resp: AxiosResponse = await axios.post(buildURL(this.config?.rootURL!, {path: uri}), formData, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(true);
});
}
Example #11
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async postFileRawReturn<T>(uri: string, inputName: string, file: File): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*', 'Content-Type': 'multipart/form-data'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
const formData = new FormData();
formData.append(inputName, file);
const resp: AxiosResponse = await axios.post(buildURL(this.config?.rootURL!, {path: uri}), formData, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(resp.data as T);
});
}
Example #12
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async put<T>(uri: string, data?: any): Promise<T> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
const resp: AxiosResponse = await axios.put(`${this.config?.rootURL}${uri}`, data, config);
return new Promise<T>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
if (resp.data.isError) reject(resp.data.value);
resolve(resp.data.value as T);
});
}
Example #13
Source File: client.ts From Deep-Lynx with MIT License | 6 votes |
private async putNoData(uri: string, data: any, queryParams?: {[key: string]: any}): Promise<boolean> {
const config: AxiosRequestConfig = {};
config.headers = {'Access-Control-Allow-Origin': '*'};
config.validateStatus = () => {
return true;
};
if (this.config?.auth_method === 'token') {
config.headers = {Authorization: `Bearer ${RetrieveJWT()}`};
}
if (this.config?.auth_method === 'basic') {
config.auth = {username: this.config.username, password: this.config.password} as AxiosBasicCredentials;
}
let url: string;
if (queryParams) {
url = buildURL(this.config?.rootURL!, {path: uri, queryParams: queryParams!});
} else {
url = buildURL(this.config?.rootURL!, {path: uri});
}
const resp: AxiosResponse = await axios.put(url, data, config);
return new Promise<boolean>((resolve, reject) => {
if (resp.status < 200 || resp.status > 299) reject(resp.data.error);
resolve(true);
});
}