Create A Simple CRUD Service
In this tutorial we will create A Simple User CURD service.
classmap UserItem User { [ target_path : "." ; class_mgr : UserMgr ; class_http_mgr : UserHttpMgr ; dispatch_method : uri ; mode_debug : 1; class_validator : CSHttpFormValidator MinLen,MaxLen,RangLen,Number,Mobile,StartWith,GTE,EQ,LTE,GT,LT ; sql_connection : "server=127.0.0.1,username=test,password=test,database=test" ; app_info : [ service_name : "UserServ"; service_desc : "User CRUD Service"; service_comment: ""; service_port : "8001"; service_platform: "linux"; file_cfg : "/etc/userserv.ini"; file_pid : "/var/run/userserv.pid"; cron_enable : 0; cmd_limitips : "127.0.0.1"; status_enable : 1; unload_enable : 1; log_enable : 1; log_file : "userlog"; log_path : "/var/log/user"; run_user : root; run_group : root; db_server : "127.0.0.1"; db_port : "3306"; db_username: "test"; db_userpwd : "test"; db_name : "test"; ]; error_codes : [ // 'API_REQUEST_INVALID' => array(99001, "request invalid"), 'API_REQUEST_EXPIRED' => array(99002, "request expired"), 'API_REQUEST_AUTHORIZED_FAILED' => array(99003, "unauthorized"), 'API_OPERATION_UNDEFINED' => array(99999, "undefined request"), 'API_NO_RECODE' => array(99004, "has no record"), ]; ] User : users { [ ("Users Info") comment : "User Info" fields_list : "id,username,useremail,addtime,status" ; fields_create: "username,useremail" ; fields_update: "" ; field_id : id ; http_method : "user" C R U D; ] // Class Field [JSON Field] (HTTP Param) , Table Field : Field Type (IDX Type) id [id] (id) ,id :int (id); ("User Name") username [username] (username) ,username :string(key); ("User Email") useremail [useremail] (useremail) ,useremail :string(key); ("User Add Time") addtime [addtime] (addtime) ,addtime :idate; ("User Status") status [status] (status) ,status :int ; }
use the REST Service Code Helper we got these server side files:
UserItem.h UserItem.cpp UserMgr.h UserMgr.cpp UserHttpMgr.h UserHttpMgr.cpp UserServ.cpp AppServerDefs.h Makefile start.sh stop.sh
Modify Makefile set the correct include path and library path.
execute
make
get the UserServ,
execute
./start.sh