JSON 端点
通知目标格式
Section titled “通知目标格式”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。
添加请求头和请求体字段
Section titled “添加请求头和请求体字段”解码后以空格开头的查询参数键会成为请求头;以 : 开头的键会成为额外的请求体字段。
jsons://example.com/notifications?%20Authorization=Bearer%20TOKEN&:environment=production这会发送 Authorization: Bearer TOKEN,并在 JSON 请求体中添加 "environment": "production"。其他查询参数会保留在端点 URL 中。
提供方专属选项
Section titled “提供方专属选项”json.send() 和 jsons.send() 直接接受 ofetch 的 FetchOptions:
import { jsons } from 'statocysts'
await jsons.send(target, notification, { timeout: 5000, retry: 2,})