@chuxingpay/ts-soa-sdk

Fuxun SOA Services SDK By TypeScript

Usage no npm install needed!

<script type="module">
  import chuxingpayTsSoaSdk from 'https://cdn.skypack.dev/@chuxingpay/ts-soa-sdk';
</script>

README

ts-soa-sdk

Fuxun SOA Services SDK By TypeScript

依赖

安装

npm i @chuxingpay/ts-soa-sdk

Examples

调用fuxun-os接口

const { SOARequest, UserDefinition } = require('ts-soa-sdk')

// 使用内置定义
SOARequest.build(UserDefinition)
const userApi = new SOARequest({ name: 'fuxun-os', version: '1.3.2' })

const token = 'this is token'
userApi.setToken(token)

// 使用链式函数调用(需调用 build 函数传入接口定义)
const { body } = await userApi.users('5e05aabbe822584091f4ef55').policies()

// 使用链接调用(无需 build)
const { body } = await userApi.post('/users/5e05aabbe822584091f4ef55/policies')

调用 soa 服务接口

// 手动传入定义
SOARequest.build({
  links: [{
    href: '/reservations/list',
    method: 'POST'
  }]
})

const paymentApi = new SOARequest({ name, version })
paymentApi.setHost('http://soapayment')

// 设置 appKey
const appKey = 'this is appkey'
paymentApi.setAppKey(appKey)

const { body } = await paymentApi.reservations().list().exec({
  headers: {
    'x-pagination-limit': 20,
    'x-pagination-no': 1
  }
})