Skip to content

Instantly share code, notes, and snippets.

@hedgerh
Last active January 22, 2019 17:51
Show Gist options
  • Save hedgerh/7200f94d211191258105f50f0f0196d9 to your computer and use it in GitHub Desktop.
Save hedgerh/7200f94d211191258105f50f0f0196d9 to your computer and use it in GitHub Desktop.
Example http module with Axios
import axios from 'axios'
export const http = axios.create({
baseUrl: 'https://localhost:3000',
headers: {
//...
},
})
http.interceptors.response.use(response => response.data, err => throw new Error(err))
export const fetchPosts = () => http.get('/posts')
export const fetchUser = (id) => http.get(`/users/${id}`)
export const login = (email, password) => http.post('/login', { email, password })
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment