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

@hongfangze/http-request

v0.1.1

Published

comm.http-request

Downloads

11

Readme

@hongfangze/request HTTP请求帮助类

介绍

发送HTTP请求:

import { HttpRequest } from "@hongfangze/http-request";

// 实例化请求对象
const httpRequest = new HttpRequest("http://localhost:80",[headers:Record<string,string>],[timeout:number]);

/**
* 发送请求
* @param {string} [url] 请求地址,请注意,无需包含baseUrl,默认“/”
* @param {("GET" | "POST" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS")} [method] 请求方式,默认“GET”
* @param {Record<string, any>} [query] 地址栏请求参数,会用&key=value的方式连接
* @param {Record<string, any>} [body] 请求包体,会以JSON的方式发送,WHATGW标准:GET及HEAD不支持该参数
* @param {Record<string, string>} [headers] 额外的请求头部
* @return {*}  {Promise<IHttpResponse>} 请求返回数据
* @memberof requestInstance
*/
httpRequest.send(url?: string, method?: "GET" | "POST" | "PATCH" | "DELETE" | "HEAD" | "OPTIONS", query?: Record<string, any>, body?: Record<string, any>, headers?: Record<string, string>): Promise<IHttpResponse>

/**
 * 下载文件
 * @param {string} [url] 请求地址,请注意,无需包含baseUrl,默认“/”
 * @param {string} [downloadFilename] 保存的文件全路径及文件名,不传则自动处理保存在当前目录下
 * @param {("GET" | "POST")} [method] 请求方式,默认“GET”
 * @param {Record<string, any>} [query] 地址栏请求参数,会用&key=value的方式连接
 * @param {Record<string, any>} [body] 请求包体,会以JSON的方式发送,WHATGW标准:GET及HEAD不支持该参数
 * @param {Record<string, string>} [headers] 额外的请求头部
 * @return {*}  {Promise<IHttpDownloadResponse>} 请求响应
 * @memberof httpRequest
 */
async download(url?: string, downloadFilename?: string, method?: "GET" | "POST", query?: Record<string, any>, body?: Record<string, any>, headers?: Record<string, string>): Promise<IHttpDownloadResponse>

/**
 * 上传文件
 * @param {string} [url] 请求地址,请注意,无需包含baseUrl,默认“/”
 * @param {("POST" | "PATCH" | "PUT")} [method] 请求方式,默认“POST”
 * @param {Record<string, any>} [query] 地址栏请求参数,会用&key=value的方式连接
 * @param {IFormData[]} [body] 请求包体,会以JSON的方式发送
 * @param {Record<string, string>} [headers] 额外的请求头部
 * @return {*}  {Promise<IHttpResponse>} 请求响应
 * @memberof httpRequest
 */
async upload(url?: string, method?: "POST" | "PATCH" | "PUT", query?: Record<string, any>, body?: IFormData[], headers?: Record<string, string>): Promise<IHttpResponse>

/**
 * 发送FormData数据
 * @param {string} [url] 请求地址,请注意,无需包含baseUrl,默认“/”
 * @param {("POST" | "PATCH" | "PUT")} [method] 请求方式,默认“GET”
 * @param {Record<string, any>} [query] 地址栏请求参数,会用&key=value的方式连接
 * @param {Record<string, string>} [body] 请求包体,会以FormData的方式发送
 * @param {Record<string, string>} [headers] 额外的请求头部
 * @return {*}  {Promise<IHttpResponse>} 请求响应
 * @memberof httpRequest
 */
async formdata(url?: string, method?: "POST" | "PATCH" | "PUT", query?: Record<string, any>, body?: Record<string, string>, headers?: Record<string, string>): Promise<IHttpResponse>

版本迭代记录

2024-11-07 v0.1.1

  • 增加formdata,用于将body转换成formdata数据后发送

2024-11-06 v0.1.0

  • 增加download,用于下载文件
  • 增加upload,用于上载文件
  • 优化send,正常返回status等数据

2024-11-05 v0.0.2

  • 忽略HTTPS证书错误

2024-07-28 v0.0.1

  • 实现基础的请求函数封装
  • 后期将增加其他的封装