Rules Code:    |  BEFORE |  AFTER |  AUTHORIZATION |  ↶ BACK |  Help |        ✓PUBLISH   ♯ CHECK   Published:{{published}} ✓SAVE  ✗ CANCEL


Errors: (server reported) {{pubmessage}}

 

↶BACK

Help

RULES code reffers to javascript functions that will run server side (backend) in different circumstances to validate predefined actions. A special action is related to server security and controls user AUTHORIZATION, please read HELP documentation about default authorization method and how to implement custom methods.

RAPID REST API server operations are CRUD operations translated to CREATE - READ - UPDATE - DELETE. We can implement rules to run BEFORE and AFTER default code runs, that allows a better control on server behaviour.

Menu:
Chose one rule file (BEFORE, AFTER, AUTHORIZATION)
When changed the SAVE/CANCEL menu is shown.
Press CHECK to verify if the file does not trigger an error when required.
Press PUBLISH to move the file as resource for the server (available if CHECK returns OK).

Conventions:

- name of the function should be the name of the database table + its action like 'usersCreate','usersFind','usersUpdate', 'usersDelete' (where 'users' is our table in this sample)
- parameters are (req,atr,next)
   - 'req' the client request (Express request)
   - 'atr' attributes (function parameters sent to the server)
   - 'next' the callback function

Sample:

  	// BEFORE functions
  	module.export = {
  		...
	  	usersCreate: function(req,atr,next){
	  		atr.id = myfunction(); // create custom ID
	  		if (!atr.email){return next({error:"email required"});
	  		next()
	  	},
  		...
  	}
  	

Please read the attached documentation for more information.