# Fcapi

云函数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'
    }
})
```