@crombolo/ 交付客户端
输入的客户端 缩写 网站的 交付API,用于浏览器,节点或Bun中的应用程序. 无相依相.
npm install @crombolo/delivery-client
# in the site: write its types into the app
bunx crombolo generate --delivery --out ../app/src/cms-types.ts
import { createDeliveryClient, isExpanded } from '@crombolo/delivery-client'
import type { DeliveryTypes } from './cms-types'
const cms = createDeliveryClient<DeliveryTypes>({ baseUrl: 'https://cms.example.com' })
const page = await cms.item('/news/story', { expand: 'properties[related]' })
if (page?.contentType === 'article') {
console.log(page.properties.title)
const related = page.properties.related
if (related && isExpanded(related)) console.log(related.properties)
}
const latest = await cms.content({ fetch: 'children:/news', sort: 'createDate:desc', take: 5 })
const hits = await cms.search('harbour')
item, (中文(简体) ),items, (中文(简体) ),content, (中文(简体) ),mediaItem, (中文(简体) ),mediaItems, (中文(简体) ),media财务报告和审定财务报表search, (中文(简体) ), 与API自己的expand, (中文(简体) ),fields, (中文(简体) ),fetch, (中文(简体) ),filter财务报告和审定财务报表sort语法.apiKey, (中文(简体) ),culture, (中文(简体) ),startItem财务报告和审定财务报表memberToken选项,每个压倒性 每个请求。 在浏览器中运行的代码中保留一个API密钥.- 没有的东西
undefined; 任何其它拒绝的都会扔出一个DeliveryError联合国status财务报告和审定财务报表body。 。 。 . - 另一个来源的浏览器应用程序需要网站允许:
deliveryApi.cors.allowedOrigins。 。 。 .
该网站的文档描述API和生成的类型: docs/delivery-api.md。 。 。 .