A Sumor Cloud Tool.
More Documentation
API Middleware is a middleware for Node.JS.
It can easily expose function to api, and validate parameters
npm i @sumor/api-middleware --save
Require Node.JS version 16.x or above
As this package is written in ES module,
please change the following code in your package.json
file:
{
"type": "module"
}
plus.js
in your project folder api
export default async (context, req, res) => {
const { data } = context
const { a, b } = data
return a + b
}
plus.json
in your project folder api
{
"name": "plus",
"parameters": {
"a": {
"name": "parameter a",
"type": "number",
"length": 3
},
"b": {
"name": "parameter b",
"type": "number"
}
}
}
index.js
fileimport express from 'express'
import apiMiddleware from '@sumor/api-middleware'
const app = express()
apiMiddleware(app, process.cwd() + '/api')
app.listen(3000, () => {
console.log('Server is running on http://localhost:3000')
})
node index.js
It includes all parameters passed in the request
file upload will be parsed as below object:
name
uploaded file namesize
uploaded file size(bytes)mime
uploaded file mime type(e.g. image/png)encoding
uploaded file encoding(e.g. 7bit)path
uploaded file pathIt includes all exposed apis