fcapi

cloud function computing api generator

Usage no npm install needed!

<script type="module">
  import fcapi from 'https://cdn.skypack.dev/fcapi';
</script>

README

Fcapi

云函数http触发器实现api接口

安装

npm i fcapi

使用

  • 只接受POST方法,其他类型的请求将被拒绝并返回500错误
  • 不解析URL参数
  • 请求体只接受JSON格式的数据,并且需要设置Content-Type
  • 返回的函数是底部函数,可以和其他中间件配合使用,如:mongoing
  • 逻辑内部可直接抛出错误,错误将作为结果返回
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'
    }
})