# RELE.AI Server Instance
The RBS
provides a full gRPC wrapper that simplifies the interactions with RELE.AI.
// create a new instance of the RB Server
const rbs = new RBS(conf)
# Configurations
Parameter | Type | Required | Default | Description |
---|---|---|---|---|
appId | string | Yes | N/A | Internal application ID - can be recieved by contacting support@rele.ai |
appHash | string | Yes | N/A | Internal application Hash - can be recieved by contacting support@rele.ai |
middlewares | object.<string, Function> | No | {authorizedRequest} | Set of middlewares that will be executed prior to the callback |
grpc | grpcSettings | No | See grpcSettings for more information | gRPC internal server settings. Read more here (opens new window) |
# gRPC Settings
Definition
(property) grpc: {
serverInit: {
"grpc.max_receive_message_length": number;
"grpc.max_send_message_length": number;
};
creds: grpc.ServerCredentials;
}
Default
grpc: {
serverInit: {
"grpc.max_receive_message_length": 30000000,
"grpc.max_send_message_length": 30000000
},
creds: grpc.ServerCredentials.createInsecure(),
},
# Methods
# Register Operation
registerOperation(operationKey, callback)
Params:
- operationKey: String
- callback: Function
Registers a new handler under the operation key name with the given callback.
// import the rb-server to the code
const { RBS } = require("@releai/rb-node-sdk")
const router = new RBS.Router()
// initiate the application
const rbs = new RBS({
appId: process.env.APP_ID,
appHash: process.env.APP_HASH
})
// register the hello_world operation
router.use("hello_world", (req, res) => {
res.send(200, { message: "Hello World!" })
})
// use exported router
rbs.use(router)
// initiate the listener
rbs.listen(3000)
# Use
use(handlers)
Params:
- handlers: Object
Registers multiple new handlers from a given object
handlers.js
router.use("hello_world", (req, res) => {
res.send(200, { message: "Hello World!" })
})
index.js
const handlers = require("./handlers")
rbs.use(handlers)
# Listen
listen(port, host="0.0.0.0")
Params:
- port: Number
- host: String
Initiate the listener on the provided host:port
rbs.listen(8080, "0.0.0.0")