v0.1首个正式支持的版本化规范查看版本范围

net.fetch() 非正式提议

本页不是正式 API 规范;它记录待地址绑定平台代理验证的候选契约。

执行一次有界请求—响应。目的 target、path 和方法必须符合 manifest;候选契约不跟随重定向。

Syntax

const response = await host.net.fetch(request, options?);

Parameters

NetRequest {
  target: manifest-network-target
  path: string
  method: "GET" | "HEAD" | "POST" | "PUT" | "PATCH" | "DELETE"
  headers?: HeaderMap
  body?: Bytes
  timeoutMs?: u32
}

请求/响应头白名单和 target/path 规范化规则见模块页。options?: CallOptions 提供取消信号。

Return value

{ status: u16, headers: HeaderMap, body: Bytes }

HTTP 4xx/5xx 正常返回,不抛 HostError。

status 只可能是最终状态码 [200, 599];1xx 和 101 协议升级不会暴露给 guest。HEAD 以及 204、205、304 的 body 固定为空。

Examples

const response = await host.net.fetch({
  target: 'catalog-api',
  path: '/v1/items',
  method: 'POST',
  headers: { 'content-type': 'application/json' },
  body: new TextEncoder().encode(JSON.stringify({ name: 'demo' })),
  timeoutMs: 5_000,
});
if (response.status === 201) consume(response.body);

Errors

destination-deniedinvalid-requesttimeoutcancelledresponse-too-largeupstream-unavailable

Requirements

  • 能力:host:net.fetch
  • manifest 中声明 target、origin、path prefix 和方法
  • 可取消:是;取消不保证远端撤销已经收到的请求
  • 信任档位:lime

See also

net非正式双向中继提议

Host API 版本与分层概览Host API v0.1版本非正式提议提议canvas API呈现canvas.getInfo()方法canvas.draw()方法canvas.present()方法canvas.measureText()方法canvas.frame event事件canvas.resize event事件asset API呈现asset.read()方法asset.loadFont()方法playback API呈现playback.open()方法playback.write()方法playback.stop()方法playback.ready event事件playback.ended event事件input API输入input.focus()方法input.pointer event事件input.key event事件input.wheel event事件input.focusChange event事件ime API输入ime.openSession()方法ime.updateState()方法ime.updateGeometry()方法ime.closeSession()方法ime.textUpdate event事件ime.composition event事件ime.formatUpdate event事件ime.characterBoundsRequest event事件ime.ended event事件capture API输入capture.requestCamera()方法capture.requestMic()方法capture.frame()方法capture.readAudio()方法capture.stop()方法capture.ended event事件store API数据store.get()方法store.put()方法store.delete()方法store.list()方法store.deletePrefix()方法clipboard API数据clipboard.readText()方法clipboard.writeText()方法env API平台集成env.snapshot()方法env.change event事件开始调用 Host API指南构建交互式绘图应用指南构建自绘文本编辑器指南管理媒体采集与播放指南组织本地数据与同步指南