New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

@aplus-frontend/axios

Package Overview
Dependencies
Maintainers
0
Versions
26
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@aplus-frontend/axios

aplus reuse axios provide some methods

  • 1.1.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
113
decreased by-41.75%
Maintainers
0
Weekly downloads
 
Created
Source

Aplus axios

Repackaged axios to make it easier to send request with axios

NPM Version NPM Downloads NPM License

Quick start

//add -w in you root folder
pnpm install @aplus-frontend/axios -S -w

Methods

post

type: post<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: post method

get

type: get<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: get method

put

type: put<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: put method

delete

type: delete<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: delete method

request

type: request<T = any>(config: AxiosRequestConfig, options?: RequestOptions): Promise<T>;

tips: request method options

PropsTypedefaultexplanation
configAxiosRequestConfig-AxiosRequestConfig same as axios request config
optionsRequestOptions-RequestOptions

RequestOptions options

PropsTypedefaultexplanation
joinParamsToUrlbooleantrueSplicing request parameters to url
formatDatebooleantrueFormat request parameter time
isTransformResponsebooleantrueWhether to process the request result
isReturnNativeResponsebooleanfalseWhether to return native response headers
For example: use this attribute when you need to get the response headers
joinPrefixbooleantrueWhether to join url ,perfix will add to url by default
apiUrlstring-Interface address, use the default apiUrl if you leave it blank
urlPrefixstring-url perfix
errorMessageMode'none'| 'modal'|'message'|'notice'-Error message prompt type
successMessageMode'none'| 'modal'|'message'|'notice'-Success message prompt type
joinTimebooleantrueWhether to add a timestamp,It's will add Timestamp to query params if request type is get
ignoreCancelTokenbooleanfalseIgnore duplicate requests
withTokenbooleantrueWhether to send token in header
retryRequestObject {isOpenRetry: true,count: 5,waitTime: 100}Request retry Strategy
customSuccessMessagestring-Custom success prompt
closeErrorModalbooleanfalseClose error modal

useage example with vue3

You can customize a global hooks method useDefHttp.ts like below:

import { defHttp as _defHttp, VAxios } from '@aplus-frontend/axios'

export function useDefHttp() {
  const globSetting = useGlobSetting()
  const urlPrefix = globSetting.urlPrefix
  const userStore = useUserStoreWithOut()
  const localeStore = useLocaleStore()
  const defHttp = _defHttp({
    apiUrl: globSetting.apiUrl,
    urlPrefix: urlPrefix,
    useMessageHook: useMessage,
    getToken: getToken,
    setToken: userStore.setToken,
    logout: () => {
      if (qiankunWindow.__POWERED_BY_QIANKUN__) {
        qiankunWindow.setGlobalState({
          redirectTo: PageEnum.BASE_LOGIN,
          token: setAuthCache(TOKEN_KEY, undefined),
        })
      } else {
        userStore.logout()
      }
    },
    getLocale: localeStore.getLocale,
  })
  return {
    defHttp,
  }
}

after you can write methods in your project api folder

import { useDefHttp } from '@/hooks/web/useDefHttp';
const { defHttp } = useDefHttp();

//base useage whit post method
export function inventoryInOrderListApi(params: model.InventoryInParams) {
  return defHttp.post<BasicFetchResult<model.InventoryInOrderItem[]>>({
    url: UrlMap.InventoryInOrderList,
    params
  });
}

//Set the return result to blob and close the error pop-up window
export function exportInOrderDetails() {
  return defHttp.post<Blob>(
    {
      url: UrlMap.ExportDetailList,
      responseType: 'blob'
    },
    {
      isTransformResponse: false,
      closeErrorModal: true
    }
  );
}

Keywords

FAQs

Package last updated on 12 Dec 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