Skip to content

Instantly share code, notes, and snippets.

@dharavp
Created April 3, 2019 05:26
Show Gist options
  • Save dharavp/8abbafbc39a1eac1cb19236cd516b0e1 to your computer and use it in GitHub Desktop.
Save dharavp/8abbafbc39a1eac1cb19236cd516b0e1 to your computer and use it in GitHub Desktop.
import axios from 'axios';
export const getApi = (url) => {
return new Promise((resolve, reject) => {
axios.defaults.headers.common.Authorization = '';
axios.get(url)
.then((response) => {
resolve(response)
})
.catch((error) => {
reject(error)
});
})
};
export const postApi = (url, AuthToken, formData) => {
return new Promise((resolve, reject) => {
axios.defaults.headers.common.Authorization = AuthToken;
axios.post(url, formData)
.then((response) => {
if (response.data !== null) {
const statusCode = response.data.status_code;
if (statusCode === 200) {
resolve(response)
}
}
})
.catch((error) => {
reject(error)
});
})
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment