@absolutejs/http (英语)
为绝对JS应用程序提供中和,原产地锁定的HTTP.
import { http } from '@absolutejs/http';
const orders = await http.get<Order[]>('/api/orders');
await http.post('/api/orders', { sku: 'absolute-shirt', quantity: 1 });
应用程序代码在浏览器,PWA和Capacitor构建之间保持不变. 这个 浏览器运输使用同源HTTP-只使用饼干. 绝对JS安装 与本地Auth客户的可再生无记名证书进行电容运输; 符号从不输入页面代码.
担保合同
- 相对 URL 解决一个配置的应用程序源 .
- 绝对 URL 必须匹配该确切来源 .
- HTTPS需要外部回回回发展.
- 应用程序提供
Authorization, (中文(简体) ),Cookie,以及Proxy-Authorization头被拒绝。 运行时提供者拥有证书. - 已禁用可信任请求的再定向 重定向从证书或请求机构转发通道.
- HTTP 错误显示状态和 URL,但不自动复制私密文件 反应体变成例外或诊断.
使用 http.request() 当你需要生的 Response, (中文(简体) ), http.text() 用于文本,以及
http.json() 或者JSON的方法帮手. @absolutejs/sync 仍为
持久本地首个API;普通的HTTP是连接先.
类型参数描述调用站点的解码结果. 用于端到端
路线推论,通过 http.fetch 进入您使用的Elysia Eden客户端
因此,Eden保留了服务器路由类型,而AbsoluteJS则拥有
运行时间运输.
明确运输
SSR代码必须安装或构建请求范围运输,而不是 猜测公共来源:
import { createAbsoluteHttpClient } from '@absolutejs/http';
import { createSsrHttpTransport } from '@absolutejs/http/ssr';
const http = createAbsoluteHttpClient({
transport: createSsrHttpTransport({
origin: 'https://app.example.com'
})
});
测试可以使用 createTestHttpTransport() 从 @absolutejs/http/testing。 。 。 .