Created
October 29, 2016 18:38
-
-
Save ivan-hilckov/8d1ffb1c57c9de3c771d96665bbf15c1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import axios from 'axios'; | |
import { baseUrl } from 'config'; | |
export default function request(path, method, params, data, token, eteg) { | |
const headers = {}; | |
if (token) { | |
headers['Authorization'] = token; // eslint-disable-line dot-notation | |
} | |
if (eteg) { | |
headers['If-Match'] = eteg; | |
} | |
return axios({ | |
url: path, | |
baseURL: baseUrl, | |
headers, | |
method, | |
params, | |
data, | |
}).then((response) => (response)) | |
.catch((err) => ({ err })); | |
} | |
export const getApi = (url, params, data, token) => request(url, 'get', params, data, token); | |
export const postApi = (url, params, data, token) => request(url, 'post', params, data, token); | |
export const putApi = (url, params, data, token) => request(url, 'patch', params, data, token); | |
export const patchApi = (url, params, data, token, eteg) => request(url, 'get', params, data, token, eteg); | |
export const deleteApi = (url, params, data, token) => request(url, 'DELETE', params, data, token); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment