axios-helpers
v1.3.0
Published
helpers for get, post, delete, patch and put http methods
Downloads
110
Maintainers
Readme
Helpers
API Data
helpers for get, post, delete, patch and put http methods
// bad
const exampleCreated = await axios.post('/examples', data)
console.log(exampleCreated.data)
// good
const exampleCreated = await axios.$post('/examples', data)
console.log(exampleCreated)
Set Token
// bad
axios.defaults.headers.common['Authorization'] = token
// good
axios.setToken(token)
Set Bearer token
// bad
axios.defaults.headers.common['Authorization'] = `Bearer ${token}`
// good
axios.setToken(token, 'Bearer')
Set Base URL
// bad
axios.defaults.baseURL = 'https://example.com'
// good
axios.setBaseURL('https://example.com');
Set header
// bad
axios.defaults.headers.common['Content-Type'] = 'application/json'
// good
axios.setHeader('Content-Type', 'application/json')
Basic example
const axiosHelpers = require('axios-helpers');
const axios = axiosHelpers(require('axios'));
axios.setBaseURL('https://example.com');
const createExample = async (data) => {
const exampleCreated = await axios.$post('/examples', data)
console.log(exampleCreated)
}