fcapi
Version:
cloud function computing api generator
32 lines (25 loc) • 734 B
Markdown
云函数http触发器实现api接口
```shell
npm i fcapi
```
- 只接受`POST`方法,其他类型的请求将被拒绝并返回500错误
- **不解析**URL参数
- 请求体只接受`JSON`格式的数据,并且需要设置`Content-Type`
- 返回的函数是底部函数,可以和其他中间件配合使用,如:`mongoing`
- 逻辑内部可直接抛出错误,错误将作为结果返回
```javascript
const fcapi = require('fcapi')
exports.handler = fcapi(async (event, context) => {
switch(event.type){
case 'one':
return await one(event)
case 'another':
return await two(event)
default:
throw 'Unknown type'
}
})
```