Skip to content

Instantly share code, notes, and snippets.

@197291
Created April 16, 2018 07:29
Show Gist options
  • Save 197291/fd854b23466e2f68cc37926b491b9fc1 to your computer and use it in GitHub Desktop.
Save 197291/fd854b23466e2f68cc37926b491b9fc1 to your computer and use it in GitHub Desktop.
export default class Api {
get(url: string, config?: AxiosRequestConfig) {
return new Promise((resolve, reject) => {
axios.get(BASE_URL + url, config)
.then(({data}) => resolve(data))
.catch(error => reject(error));
});
}
put(url: string, _data: any = {}) {
return new Promise((resolve, reject) => {
axios.put(BASE_URL + url, _data)
.then(({data}) => resolve(data))
.catch(error => reject(error));
});
}
post(url: string, _data: any = {}) {
return new Promise((resolve, reject) => {
axios.post(BASE_URL + url, _data)
.then(({data}) => resolve(data))
.catch(error => reject(error));
});
}
delete(url: string) {
return new Promise((resolve, reject) => {
axios.delete(BASE_URL + url)
.then(({data}) => resolve(data))
.catch(error => reject(error));
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment