Skip to content

Instantly share code, notes, and snippets.

@thiagovilla
Created August 22, 2018 18:56
Show Gist options
  • Save thiagovilla/9755f964073e0da3bff13f6a2e6b1401 to your computer and use it in GitHub Desktop.
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
// 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