1.3.0 • Published 3 years ago

axios-helpers v1.3.0

Weekly downloads
7
License
ISC
Repository
github
Last release
3 years ago

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)
}
1.3.0

3 years ago

1.2.1

3 years ago

1.2.0

3 years ago

1.1.0

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago