Skip to content

Instantly share code, notes, and snippets.

@sultaniman
Last active August 31, 2019 19:42
Show Gist options
  • Save sultaniman/88c24066e7bfd283f64145eef7b19e7f to your computer and use it in GitHub Desktop.
Save sultaniman/88c24066e7bfd283f64145eef7b19e7f to your computer and use it in GitHub Desktop.
/*
* Wraps axios and provides
* more convenient post method
* calls with payload data
*/
export function post(uri, data) {
return axios.post(uri, data, {
headers: getHeaders(),
withCredentials: true
})
}
/*
* Wraps axios and provides
* more convenient put method
* calls with data
*/
export function put(uri, data) {
return axios.put(uri, data, {
headers: getHeaders(),
withCredentials: true
})
}
/*
* Wraps axios and provides
* more convenient delete method
*/
export function remove(uri) {
return axios.delete(uri, {
headers: getHeaders(),
withCredentials: true
})
}
/*
* Wraps axios and provides
* more convenient get method
* calls with data.
*/
export function get(uri, data = {}) {
if (Object.keys(data).length > 0) {
uri = `${uri}?${qs(data)}`
}
return axios.get(uri, {
headers: getHeaders(),
withCredentials: true
})
}
export function upload(uri, data) {
return fetch(uri, {
headers: getHeaders(true),
cors: true,
method: 'POST',
body: data
})
}
@douglasg14b
Copy link

douglasg14b commented Aug 31, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment