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

dl-http

v1.0.5

Published

基于axios,封装的http工具

Downloads

2

Readme

安装

npm install dl-http

更新说明

2023-08-03 (version 1.0.0)

  1. 基础版本发布

使用说明

实例:

import Request from "dl-http"

// 获取实例,自定义配置
const http = Request({
    // ...自定义配置
    baseURL:"http://127.0.0.1:3001",
    headers:{ "Content-Type":"application/json;charset=utf-8"},
    timeout: 10 * 1000,
    responseType: 'json',
    stateMachineCode:{  // 自定义响应消息
        "5000":"token失效"
    },
    interceptorHooks:{
		requestInterceptor:(require)=>{
    		// ...请求前回调
    		return require
		},
		requestInterceptorCatch:(error)=>{
            // ...请求异常回调
			return error
        },
      	responseInterceptor:(response)=>{
            // ...响应前回调
            // 注:建议不要重写,自行重写将自定义状态消息将失效。
            return response
        },
      	responseInterceptorCatch:(error)=>{
            // ...响应异常回调
            return error
        }
	}
    // ...自定义配置
})

// 发起get请求
http.get("/getMenuList")
.then((res)=>{
    console.log(res);
})
.catch((err)=>{
    console.log("err:",err);
})

// 发起post请求
http.post("/setUser",{name:"小明",age:18})
.then((res)=>{
    console.log(res);
})
.catch((err)=>{
    console.log("err:",err);
})

API文档

config 配置

| 属性 | 默认值 | 说明 | | :--------------: | :---------------------: | :----------------------------------------------------------: | | baseURL | 无 | baseURL 将自动加在 url 前面,除非 url 是一个绝对 URL。 | | headers | 无 | 自定义请求头 | | timeout | 默认值是 0 (永不超时) | 指定请求超时的毫秒数 | | stateMachineCode | 无 | 自定义响应文案 | | interceptorHooks | 无 | 拦截器 | | withCredentials | false | 表示跨域请求时是否需要使用凭证 | | responseType | json | 表示浏览器将要响应的数据类型,选项包括: 'arraybuffer', 'document', 'json', 'text', 'stream' | | responseEncoding | utf8 | 表示用于解码响应的编码 (Node.js 专属) | | xsrfCookieName | XSRF-TOKEN | xsrfCookieName 是 xsrf token 的值,被用作 cookie 的名称 | | xsrfHeaderName | X-XSRF-TOKEN | xsrfHeaderName 是带有 xsrf token 值的http 请求头名称 | | maxContentLength | 2000 | maxContentLength 定义了node.js中允许的HTTP响应内容的最大字节数 | | maxBodyLength | 2000 | maxBodyLength(仅Node)定义允许的http请求内容的最大字节数 |

请求方法

GET 请求

  /**
   * GET 请求
   * @param url 请求地址 (必填)
   * @param params 请求参数
   * @param config 自定义配置
   * @returns Promise 对象
   */
  get(url, params, config) 

POST 请求

  /**
   * POST 请求
   * @param url 请求地址 (必填)
   * @param params 请求参数
   * @param config 自定义配置
   * @returns Promise 对象
   */
  post(url, params, config) 

DELETE 请求

/**
   * DELETE 请求
   * @param url 请求地址 (必填)
   * @param params 请求参数
   * @param config 自定义配置
   * @returns Promise 对象
   */
  delete(url, params, config)

PATCH 请求

  /**
   * PATCH 请求
   * @param url 请求地址 (必填)
   * @param params 请求参数
   * @param config 自定义配置
   * @returns Promise 对象
   */
  patch(url, params, config)

PUT 请求

/**
   * PUT
   * @param url 请求地址
   * @param params 请求参数
   * @param config 自定义配置
   * @returns Promise 对象
   */
  put(url, params, config)

自定义请求

  /**
   * 自定义请求
   * @param url 请求地址
   * @param params 请求参数
   * @param method 请求类型 例如:get,post,delete等...
   * @param config 自定义配置
   * @returns Promise 对象
   */
  request(url, params, method, config)