Created
August 22, 2018 18:56
-
-
Save thiagovilla/9755f964073e0da3bff13f6a2e6b1401 to your computer and use it in GitHub Desktop.
Axios-wrapped global API service with JWT authentication and base URL environment variable
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
// api.js | |
import axios from 'axios' | |
const API_URL = process.env.API_URL | |
const AUTH_TOKEN = ... // from local storage, session etc. | |
const api = axios.create({ | |
baseURL: API_URL, | |
headers: { 'Authorization': 'JWT ' + AUTH_TOKEN } | |
}) | |
export default api |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment