CS lib
This commit is contained in:
parent
cec664c8d0
commit
ff2320f08c
13 changed files with 297 additions and 297 deletions
|
@ -2,70 +2,70 @@ import axios from 'axios';
|
|||
|
||||
const API_URL = 'https://kliko.maartenvr98.nl/api/v1/';
|
||||
const CONFIG = {
|
||||
timeout: 30000,
|
||||
timeout: 30000,
|
||||
};
|
||||
|
||||
export class Request {
|
||||
/**
|
||||
* Send GET request to API
|
||||
*
|
||||
* @param url
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static get(url: string, headers = {}) {
|
||||
return axios
|
||||
.get(API_URL + url, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send GET request to API
|
||||
*
|
||||
* @param url
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static get(url: string, headers = {}) {
|
||||
return axios
|
||||
.get( API_URL + url, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
} )
|
||||
.then( response => response.data )
|
||||
.catch( error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send POST request to API
|
||||
*
|
||||
* @param url
|
||||
* @param body
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static post(url: string, body = {}, headers = {}) {
|
||||
return axios
|
||||
.post(API_URL + url, body, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send POST request to API
|
||||
*
|
||||
* @param url
|
||||
* @param body
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static post(url: string, body = {}, headers = {}) {
|
||||
return axios
|
||||
.post( API_URL + url, body, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
} )
|
||||
.then( response => response.data )
|
||||
.catch( error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
} );
|
||||
}
|
||||
|
||||
/**
|
||||
* Send PUT request to API
|
||||
*
|
||||
* @param url
|
||||
* @param body
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static put(url: string, body = {}, headers = {}) {
|
||||
return axios
|
||||
.put(API_URL + url, body, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
})
|
||||
.then(response => response.data)
|
||||
.catch(error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
});
|
||||
}
|
||||
/**
|
||||
* Send PUT request to API
|
||||
*
|
||||
* @param url
|
||||
* @param body
|
||||
* @param headers
|
||||
* @returns {Promise<AxiosResponse<any>>}
|
||||
*/
|
||||
static put(url: string, body = {}, headers = {}) {
|
||||
return axios
|
||||
.put( API_URL + url, body, {
|
||||
...CONFIG,
|
||||
...headers,
|
||||
} )
|
||||
.then( response => response.data )
|
||||
.catch( error => {
|
||||
// Handle error
|
||||
throw error;
|
||||
} );
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue