Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@rainxh11/axios-wrapper

Package Overview
Dependencies
Maintainers
1
Versions
3
Alerts
File Explorer

Advanced tools

Socket logo

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.

  • 1.3.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
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

Package last updated on 11 Mar 2024

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc