Created
January 17, 2020 04:57
-
-
Save manakuro/3bb40e40af593208637c37512cbbe1a1 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, { AxiosRequestConfig, AxiosResponse } from 'axios' | |
import { API_URL } from '../const' | |
const api = axios.create({ | |
baseURL: API_URL, | |
headers: { | |
'Content-Type': 'application/json', | |
}, | |
responseType: 'json', | |
}) | |
const setToken = (token: string) => { | |
api.defaults.headers['Authorization'] = `Bearer ${token}` | |
} | |
const post = <T = any, R = AxiosResponse<T>>( | |
url: string, | |
data?: any, | |
config?: AxiosRequestConfig, | |
): Promise<R> => { | |
return api.post<T, R>(url, data, config) | |
} | |
export default { | |
setToken, | |
post, | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment