0.1.0 • Published 5 months ago

@bale-wasm/http v0.1.0

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

wasm-http

use rust develop wasm http by Web API Request

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.0

5 months ago