跳转到内容

JSON 端点

协议
json:jsons:
运行时
Node.js浏览器
json://<host>[:<port>]/<path>
jsons://<host>[:<port>]/<path>

json: 使用 HTTP,jsons: 使用 HTTPS。

import { send } from 'statocysts'
await send('jsons://example.com/notifications', {
title: 'Deployment complete',
body: 'Production is healthy.',
})

默认请求体为:

{
"title": "Deployment complete",
"body": "Production is healthy."
}

通知不含正文时会省略 body

解码后以空格开头的查询参数键会成为请求头;以 : 开头的键会成为额外的请求体字段。

jsons://example.com/notifications?%20Authorization=Bearer%20TOKEN&:environment=production

这会发送 Authorization: Bearer TOKEN,并在 JSON 请求体中添加 "environment": "production"。其他查询参数会保留在端点 URL 中。

json.send()jsons.send() 直接接受 ofetchFetchOptions

import { jsons } from 'statocysts'
await jsons.send(target, notification, {
timeout: 5000,
retry: 2,
})