npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

art-apis

v1.0.0

Published

- 接口统一管理 - 支持多 host - 支持公共配置 - 支持 restful 接口 - 支持重新请求

Downloads

4

Readme

基于 axios 封装的接口管理方案

  • 接口统一管理
  • 支持多 host
  • 支持公共配置
  • 支持 restful 接口
  • 支持重新请求

example

import createInstance from '../../src/apis'
import { ApisMap } from '../../src/types'

const serverMap = {
  baseServer: {
    baseMap: {
      localprod: '',
      prod: 'https://wwww.baidu.com',
      stage: 'https://wwww.baidu.com',
      test: 'https://wwww.baidu.com',
      dev: 'https:/wwww.baidu.com',
      local: 'http://127.0.0.1:4320',
      baseURL: 'https://localhost:8080'
    },
    default: true
  },
  'api-test': {
    baseMap: {
      localprod: '',
      prod: 'https://www.baidu.com',
      stage: 'https://www.baidu.com',
      test: 'https://www.baidu.com',
      dev: 'https:/www.baidu.com',
      local: `http://127.0.0.1:4320`,
      baseURL: 'https://localhost:8080'
    }
  }
}

const apiMap: ApisMap = {
  getBaseInfo: {
    method: 'get',
    url: '/base/get'
  },
  getBaseRestInfo: {
    method: 'get',
    url: '/base/get/:id/kill/:test'
  }
}

/**
 * 测试拦截器
 */
createInstance.useReq(
  function(config) {
    console.log('请求中间拦截器1')
    config.headers.Authorization = 'Bearer'
    return config
  },
  function(error) {
    return Promise.reject(error)
  }
)
createInstance.useReq(
  function(config) {
    console.log('请求中间拦截器2')
    config.headers.Authorization = 'Bearer'
    return config
  },
  function(error) {
    return Promise.reject(error)
  }
)

createInstance.useRes(
  function(result) {
    console.log('响应中间拦截器')
    return result
  },
  function(error) {
    return Promise.reject(error)
  }
)

let apis = createInstance(serverMap, apiMap)

apis.getBaseInfo({ params: { name: 'vnues' } }).then(res => {
  console.log(res)
})

/**
 * 测试restful
 */

apis.getBaseRestInfo({ rest: { id: 9527, test: 250 } }).then(res => {
  console.log(res)
})

重新请求

当网断了或者请求超时,我们想要 axios 重新发起请求,如何做到?

/**
 * config配置{ retry: 5, retryDelay: 1000 }
 * 尝试retry次数
 * 隔多久进行retry
 */
axios
  .get('/some/endpoint', { retry: 5, retryDelay: 1000 })
  .then(function(res) {
    console.log('success', res.data)
  })
  .catch(function(err) {
    console.log('failed', err)
  })