Skip to content

Instantly share code, notes, and snippets.

@manakuro
Created January 17, 2020 04:57
Show Gist options
  • Save manakuro/3bb40e40af593208637c37512cbbe1a1 to your computer and use it in GitHub Desktop.
Save manakuro/3bb40e40af593208637c37512cbbe1a1 to your computer and use it in GitHub Desktop.
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