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-denied、invalid-request、timeout、cancelled、response-too-large、upstream-unavailable。
Requirements
- 能力:
host:net.fetch - manifest 中声明 target、origin、path prefix 和方法
- 可取消:是;取消不保证远端撤销已经收到的请求
- 信任档位:lime