Last active
          January 22, 2019 17:51 
        
      - 
      
 - 
        
Save hedgerh/7200f94d211191258105f50f0f0196d9 to your computer and use it in GitHub Desktop.  
    Example http module with Axios
  
        
  
    
      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' | |
| 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