0.1.3 • Published 8 months ago

@bale-wasm/http v0.1.3

Weekly downloads
-
License
MIT/Apache-2.0
Repository
github
Last release
8 months ago

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

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)
0.1.2

10 months ago

0.1.1

10 months ago

0.1.3

8 months ago

0.1.0

2 years ago