MENTDB
Data Driver & Automation - Weak & Strong AI
BACK
Generate a web service from a database
Open your MQL Editor and click on the 'CONNECT' tab
Double click on the 'MENTDB' database
Right click on 'users' table, and 'GEN WS > INSERT'
Source code
#Here the generated source code, click on the play button to execute the script and your Web Service is ready, enjoy! ;
script create post "MENTDB.users.insert" false 1

  (param
  	(var "[login]" {true} "description ..." is_null:false is_empty:false "example ...")
  	(var "[password]" {true} "description ..." is_null:false is_empty:false "example ...")
  	(var "[firstname]" {true} "description ..." is_null:false is_empty:false "example ...")
  	(var "[lastname]" {true} "description ..." is_null:false is_empty:false "example ...")
  	(var "[activate]" {true} "description ..." is_null:false is_empty:false "example ...")
  	(var "[jsonconf]" {true} "description ..." is_null:false is_empty:false "example ...")
  )
  "Insert a new element into the table 'users'."
{
	
	try {
		
		#Connection ...;
		sql connect "session1" {cm get "MENTDB"};
		
		-> "[result]" (sql dml "session1" (concat 
			"INSERT INTO public.users (
				login,
				password,
				firstname,
				lastname,
				activate,
				jsonconf
			) VALUES (
				" (sql encode [login]) " ,
				" (sql encode [password]) " ,
				" (sql encode [firstname]) " ,
				" (sql encode [lastname]) " ,
				" (sql encode [activate]) " ,
				" (sql encode [jsonconf]) "
			);"
		));
		
		#Disconnection ...;
		sql disconnect "session1";
		
		# Return the json;
		[result]
		
	} {

		#Close the connection;
		try {sql disconnect "session1"} {} "[sub_err]";

		#Generate an error;
		exception (1) ([err]);
		
	} "[err]";
	
} "Return the number of impacted lines.";
Connect to your application portal (https://localhost:9999/) and click on 'REST API'
Click on 'Login'
Enter the login 'admin' and the default password 'pwd'
Click on 'POST' method for the script 'MENTDB/users/insert'
You can see the web service description for the generated script 'MENTDB/users/insert'. You can use PHP or other language to call this WS.
Go down and you can try the web service with a HTML form...