Socket
Socket
Sign inDemoInstall

@rainxh11/axios-wrapper

Package Overview
Dependencies
10
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @rainxh11/axios-wrapper

Axios Wrapper, which allows working with Axios to be less messy, more concise, clear, and functional.


Version published
Weekly downloads
0
decreased by-100%
Maintainers
1
Created
Weekly downloads
 

Readme

Source

Axios Wrapper

a wrapper that allows working with Axios to be less messy, more concise, clear, and functional.

Install

yarn add @rainxh11/axios-wrapper

# npm
npm install --save @rainxh11/axios-wrapper

Usage Example:

import { createAxios } from '@rainxh11/axios-wrapper'

// create an axios instance & request function
const { client: httpClient, createRequestFn } = createAxios(instance => {
  // with custom instance interceptors, configurations...etc
    instance.interceptors.request.use(req => {
      console.log(`${req.method}`, req.url)
      req.headers.Authorization = `Bearer ${getSomeToken()}`
    })
    return instance
  },
  // Axios Defaults
  {
    baseURL: 'https://random-data-api.com/api/v2',
    headers: {
      'Content-Type': 'application/json',
    },
  },
)

// create a request wrapper function that supports cancellation with AbortSignal
const getUsers = createRequestFn((client, { size }, signal) =>
  client.get('/users', { params: { size }, signal }),
)

const users = await getUsers({ size: 2 })

// with react-query
import { useQuery } from 'react-query'

function UserListComponent() {
  const [size, setSize] = useState(2)
  const {
    data,
    isLoading,
  } = size =>
    useQuery(['users', size], ({ signal }) => getUsers({ size }, signal))
    /*
        ....
    */
}

Keywords

FAQs

Last updated on 11 Mar 2024

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc