1.3.1 • Published 3 years ago
funcserver v1.3.1
FuncServer
A simple yet fast and powerful JSON based Backend Framework to build Next Generation API's for Node JS
Installation
Install my-project with npm
npm install funcserver
Usage/Examples
import the package
const { FuncServer } = require("funcserver")
create The server
const server = new FuncServer()
Register Your Functions
Note: Only Use function syntax and not arrow Functions
function hello(name = "World!") { return `hello ${name}` }
server.register(hello)
Any JSON serializable data can be returned from the function
### To give a cutom name to call from the client
```javascript
server.register([hello, "customName"])
Namespaced functions can also be created
// import createNamespace
const { createNamespace } = require("funcserver")
// create a Namespace
const usersNs = createNamespace("users")
// register functions
function getAll() {
return "All Users"
}
usersNs.register(getAll)
// register Namespace
server.registerNamespace(usersNs)
Namespaced Functions can be Accessed through
namespaceName.functionName
syntax
Start the server
const PORT = process.env.PORT || 1234
server.start(PORT)
You can pass optional Koa compatible middleware after the port which run before each request
Cors is Enabled by Default
Client API Reference
Call your Function
POST /func
Content-Type: application/json
{
"fun": "hello",
"args": ["Mario"]
}
Note: Args is an array of all the arguments to be passed to a function Returns JSON version of your function response