Moappi - Service is a framework for developing streamlined web apps using a combination of Node.js and client side tools such as HTML, CSS, Javascript.
$ node service.js <app name>
Provides access to the HTTP request
(object) with all request parameters from GET & POST
Example:
moappi.request.params.myParam(object) with all request cookies
Example:
moappi.request.cookies.myCookie(object) all request headers
Example:
moappi.request.headers.myHeaderGets a session parameter value
Parameters:
name(string, required) - name of the session parameter you want to getcallback(function, required) - callback function with a single parameter
Callback(err,val):
errerror if we couldn't find this varaible in the sessionvalvalues if we could find this in the session
Example:
moappi.request.session.get('user',function(err,user){
// now do something with the user
});Sets a session parameter value
Parameters:
name(string, required) - name of the session parameter you want to setval(object, required) - value you would like to set this session variable to
Example:
moappi.request.session.set('user',{'id':123});Provides access to the HTTP response
Ends the response with a status of 1
Parameters:
result(object, optional) - adds an object to the response
Response:
{"header":{"version":"0.3.4","environment":"development","status":1,"detail":"","message":""},"response":"result"}Example:
moappi.response.end("OK");Ends the response with a status of 0
Parameters:
message(string, optional) - adds a message to the response
Response:
{"header":{"version":"0.3.4","environment":"development","status":0,"detail":"","message":"error message"}}Example:
moappi.response.error("error message");Ends the response with either a status of 0 (if err) or status of 1
Parameters:
err(string, optional) - adds an error message to the responseresult(object, optional) - adds a object to the response
Example:
moappi.response.flush("error message",{});Access to the moappi api
Calls a moappi api request
Parameters:
module(string, required) - moappi modulerequest(string, required) - moappi request within the moduleparams(object, required) - parameters passed to the requestcallback(function, required) - callback when request is finished
Callback(err,data):
err(object) - error object (inc message parameter)data(object) - data result
Example:
moappi.api.call('module','request',{'param1':'test'},function(err,data){
));Queries a database configured in config file
Parameters:
sql(string, required) - SQL statementdatabase(string, required) - database name from config fileparams(object, required) - parameters passed to the querycallback(function, required) - callback when request is finished
Callback(err,data):
err(object) - error object (inc message parameter)data(object) - data result
Example:
moappi.api.query('SELECT * FROM Test','test',{'param1':'test'},function(err,data){
));(object) reference to options object in app.json config file
Example:
moappi.options.myOptionAccess to globally shared object between requests and events
Set a global variable key
Parameters:
var(string, required) - variable namekey(string, required) - variable keyval(object, required) - variable value
Example:
moappi.global.set("myVar","myKey","myVal");Gets a global variable key
Parameters:
var(string, required) - variable namekey(string, required) - variable keycallback(function, required) - callback function
Callback(err,val):
err(object) - err (if any)val(object) - variable key value
Example:
moappi.global.get("myVar","myKey",function(err,val){
});ZeroMQ API
Broadcast emit on configured ZMQ named channel
Parameters:
name(string, required) - name of ZMQ channelobj(object, required) - object to broadcast on channel
Example:
moappi.zmq.broadcast.emit("channel",{"myObj":12});Socket access (socket.io)
Emit on socket
Parameters:
id(string, required) - socket id to emit tochannel(string, required) - channel to emit todata(object, required) - data to send on channel
Example:
moappi.socket.emit("123","channel",{"myObj":12});Broadcast on socket
Parameters:
id(string, required) - socket id to broadcast onchannel(string, required) - channel to broadcast ondata(object, required) - data to send on channel
Example:
moappi.socket.broadcast("123","channel",{"myObj":12});Connected to socket
Parameters:
id(string, required) - socket id to wait until connectedcallback(function, required) - callback when connected
Example:
moappi.socket.connected("123",function(){
//Socket ready
});OAUTH Requests
(object) Access to OAUTH config
Example:
moappi.oauth.config.myConfigMake an OAUTH call from list of requests in config file
Parameters:
kind(string, required) - oauth kind to call (from config file)request(string, required) - oauth request to call (from config file)params(object, required) - params to send to oauth callcallback(function, required) - callback when oauth is completed
Callback(err,val):
err(object) - err (if any)data(object) - data returned from OAUTH call
Example:
moappi.oauth.call('google','account',{'param1':'test'},function(err,data){
});SQL helper requests
Format value for data type & encode special characters
Parameters:
val(object, required) - value to formattype(string, optional) - either 'string' or 'number'limit(object, optional) - limit size of a string
Returns:
(string) - returns formatted string
Example:
moappi.sql.format('test string','string',10)Format values for data type & encode special characters
Parameters:
arry(array, required) - values to formattype(string, optional) - either 'string' or 'number'limit(object, optional) - limit size of a string
Returns:
(array) - returns an array of formatted string
Example:
moappi.sql.format(['str1','str2'],'string',10)