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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@bale-wasm/http

v0.1.2

Published

use `rust` develop `wasm` `http` by `Web API Request`.

Downloads

147

Readme

wasm-http

use rust develop wasm http by Web API Request

Webpack5

target: ['web', 'es2020'],
experiments: {
  asyncWebAssembly: true
}

Usage

It is necessary to determine whether the browser supports wasm

if (typeof WebAssembly === 'object' && typeof WebAssembly.instantiate === 'function') {
  // 浏览器支持WebAssembly
  console.log('WebAssembly is supported')
} else {
  // 浏览器不支持WebAssembly
  console.log('WebAssembly is not supported')
}

To use wasm, first import this to your file:

npm install @bale-wasm/http
import { send } from '@bale-wasm/http/lib/wasm_http'

Explanation

  • Request 文档地址: https://developer.mozilla.org/zh-CN/docs/Web/API/Request

  • opts 定义了 urlmethoddataformheaders 等属性。

    • url string 类型, 全路径。

    • method 可选 string 类型, POSTGET, 默认为 POST

    • form FormData 类型, 用于文件上传等。

    • headers object 类型, 定义 header 头。

    • timeout 可选 number 类型, 定义 超时时间, -1不超时, 默认为 30s

    • isFormSubmit 可选 bool 类型, 是否通过 form 表单 提交。

  • request 定义了 cachecredentialsintegritymoderedirectreferrerreferrer_policyreferrer_policysignal 等。

    • cache 分为: defaultno-storereloadno-cacheforce-cacheonly-if-cached, 默认为 default。 文档地址: https://developer.mozilla.org/zh-CN/docs/Web/API/Request/cache

    • credentials 分为: omitsame-origininclude, 默认为 same-origin。 文档地址: https://developer.mozilla.org/zh-CN/docs/Web/API/Request/credentials

    • integrity 可选 string 类型。 文档地址: https://developer.mozilla.org/en-US/docs/Web/API/Request/integrity

    • mode 分为: same-origincorsno-cors, navigate 默认为 no-cors。 文档地址: https://developer.mozilla.org/zh-CN/docs/Web/API/Request/mode

    • redirect 分为: followerrormanual, 默认为 follow。 文档地址: https://developer.mozilla.org/en-US/docs/Web/API/Request/redirect

    • referrer 可选 string 类型。 文档地址: https://developer.mozilla.org/en-US/docs/Web/API/Request/referrer

    • referrerPolicy 分为: noneno-referrerno-referrer-when-downgradeoriginorigin-when-cross-originunsafe-urlsame-originstrict-originstrict-origin-when-cross-origin, 默认为 strict-origin-when-cross-origin。 文档地址: https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Referrer-Policy

Examples

  • 普通请求
let opts: { [K: string]: any } = {
  url: 'https://api.github.com/repos/rustwasm/wasm-bindgen/branches/master',
  method: 'get',
  headers: {
    Accept: 'application/vnd.github.v3+json'
  }
}

let response = await send(opts, null)
console.log(response)
  • FormData 请求
let formData = new FormData()
formData.append('file', file) // file 为需要上传的文件
formData.append('version', '1.0')
formData.append('text', '测试')

let updateOpts: any = {
  url: 'https://example.com/api/upload/',
  method: 'post',
  form: formData
}

let response = await send(opts, null)
console.log(response)