Skip to content

Instantly share code, notes, and snippets.

@nomanHasan
Last active January 19, 2018 14:18
Show Gist options
  • Select an option

  • Save nomanHasan/5228a180ad9da2156ca4f4e92f7972dd to your computer and use it in GitHub Desktop.

Select an option

Save nomanHasan/5228a180ad9da2156ca4f4e92f7972dd to your computer and use it in GitHub Desktop.
HttpClient #1
import axios from 'axios'
//Create a Http Client using Axios. Further modifications in this layer can be done later like Authorization.
const post = (url = '', data = '', config = {}) => {
return axios.post(url, data, config)
}
const get = (url) => {
return axios(url)
}
const put = (url = '', data = '', config = {}) => {
return axios.put(url, data, config)
}
//Cannot contain a delete method - Cause delete is a keyword.
const del = (url = '', config = {}) => {
return axios.delete(url, config)
}
//Encapsulating in a JSON object
const HttpClient = {
post,
get,
put,
delete: del
}
export {HttpClient}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment