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

@navalink/request

Package Overview
Dependencies
Maintainers
2
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@navalink/request

Dogesoft 业务请求封装库。

  • 1.0.13
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
8
decreased by-55.56%
Maintainers
2
Weekly downloads
 
Created
Source

Request

Dogesoft 业务请求封装库。

Install

# with npm
npm i @ @navalink/request

# with yarn
yarn add @navalink/request

Usage

基本使用

import $http, { EApiStatus, IResponse } from '@navalink/request';

const refreshTokenOften = async () => {
  const result = await $http.post<any, IResponse<any>>(`/api/xxx/xxx`);
  if (result.status === EApiStatus.success) {
    const data = result.data;
    // ...
  }
}

传入配置

某些场景下需要修改 axios 基础配置信息,比如 file-system 会在桌面端环境下使用不同的 url origin。

import { injectCustomization } from '@navalink/request';

injectCustomization({
  config: {
    baseURL: 'https://xxx.com',
  },
});

传递固定参数

在一些工程下,需要在每个接口内传递特定参数,比如 doty-roster 2.0 传递 app_id 信息。

import { injectCustomization } from '@navalink/request';

injectCustomization({
  baseData: {
    app_id: 'app_id value'
  }
});

定制 Response

通常,我们会根据后台接口下发的 code 区分做不同处理,比如:登录失效、没有权限等。

import { EApiStatus, injectCustomization } from '@navalink/request';

injectCustomization({
  listenResponse: (result, response) => {
    if (result.status === EApiStatus.tokenInvalid) {
      alert('请重新登录!');
    }
  }
});

动态设置 baseData

import { injectBaseData } from '@navalink/request';

injectBaseData({
  role: 'role',
});

FAQs

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