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

@txdfe/at-exceed

Package Overview
Dependencies
Maintainers
7
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@txdfe/at-exceed

axios

  • 0.3.5
  • latest
  • npm
  • Socket score

Version published
Weekly downloads
10
increased by400%
Maintainers
7
Weekly downloads
 
Created
Source
  • 用法

    import Exceed from '@alife/at-exceed';
    const apimap = [
      {
        id: 'memberSearch',
        url: '/api/members/search',
        method: 'get',
        timeout: 2000, // 设置接口超时时间
      },
    ];
    
    
    // 对apimap做一次封装,最简只需定义id和url字段
    function apimapCreator(apimapArr) {
      // 在这里可以对请求做一些统一处理,如加前缀、加headers
      return apimapArr.map(option => Object.assign(option, {
        name: option.name || option.id,
        id: option.id,
        method: option.method || 'get',
        contentType: option.type || 'application/x-www-form-urlencoded',
        urls: {
          local: `${window.UILessConfig.host}${option.url}`,
        },
        timeout: option.timeout || 3000, // 设置接口超时时间
      }));
    }
    
    const exceed = new Exceed({
      ENV: 'local',
      timeout: 3000, // 设置默认超时时间
    });
    exceed.use(apimapCreator(apimap));
    
    exceed.interceptors.request.use((config) => {
      if (config && config.headers) {
        config.headers['x-requested-with'] = 'XMLHttpRequest';
        config.headers['Authorization'] = `Bearer ${window.UILessConfig.accessToken}`;
        config.headers['X-Tenant-Id'] = `${window.UILessConfig.orgId}`;
        config.headers['X-app-id'] = `${window.UILessConfig.appId}`;
      }
      return config;
    }, (error) => {
      return Promise.reject(error);
    });
    
    exceed.interceptors.response.use(
      (response) => {
        response.status = parseInt(response.headers['x-http-status'] || response.status);
        const code = parseInt(response.data.code);
        if (code > 300 || code < 200) {
          return Promise.reject(response);
        }
        return Promise.resolve(response);
      },
      (error) => {
        return Promise.reject(error);
      },
    );
    
    export default exceed;
    
    
      import exceed from 'utils/api';
    
    
      exceed.fetch({
        api: 'memberSearch',
        data: {
          q,
        }
      }).then(res => {
        console.log(res)
      })
    
    

    注意

    如果methodpostcontentType'application/x-www-form-urlencoded',可通过qsOtions设置stringify参数的选项.

    const apimap = [
      {
        id: 'memberSearch',
        url: '/api/members/search',
        method: 'post',
        contentType: 'application/x-www-form-urlencoded',
        qsOptions: {
          allowDots: true,
        },
      },
    ];
    

FAQs

Package last updated on 02 Sep 2020

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