02 CRUD example
Using multiple commands within a single SRS file, you can implement a basic CRUD operation.
Key concepts in this example:
- Query parameter
pscope
: Used to limit the execution to a specific command.
- Server-side parameter
username
: Used to avoid including the username directly in the query string.
Example
XML |
---|
| <srs>
<def>
<itm model="param" opts="server" name="username">[[kv.v.user.username]]</itm>
<itm model="param" name="pscope" opts="req" />
<itm model="param" name="value" opts="req" />
<itm name="insert" opts="post" acl="public">
<![CDATA[
if @pscope= 'insert'
Begin
Print 'insert ' + @username + ' ' + @value
end
]]>
</itm>
<itm name="update" opts="post">
<![CDATA[
if @pscope= 'update'
Begin
Print 'update ' + @username + ' ' + @value
end
]]>
</itm>
<itm name="delete" opts="post">
<![CDATA[
if @pscope= 'delete'
Begin
Print 'delete ' + @username + ' ' + @value
end
]]>
</itm>
<itm name="select" opts="get" >
<![CDATA[
select @username + ' ' + @value as data
]]>
</itm>
</def>
</srs>
|
Bash |
---|
| curl.exe -H "Authorization:Token {token}" {host}/api/srs/102/test.json?pscope=insert
|
JSON |
---|
| {
"success": true,
"message": "insert [email protected] test\n",
"apipath": "/api/srs/102/test.json?app_name=test2&pscope=insert&value=test",
"apimethod": "POST",
"basepath": "https://app.platformaerp.com",
"filepath": "/srs/102.xml",
"name": "102",
"id": "102",
"opts": null,
"session_id": "e81753ea-df64-4faa-9a79-a5edab9c1ddf",
"label": "102",
"description": null,
"cache": null,
"executed_at": "2024-05-13T22:52:33.389664Z",
"acl": "app_test2",
"tables": [],
"def": [],
"data": {
"insert": []
}
}
|
Bash |
---|
| curl.exe -H "Authorization:Token {token}" {host}/api/srs/102/test.json?pscope=update
|
JSON |
---|
| {
"success": true,
"message": "update [email protected] test\n",
"apipath": "/api/srs/102/test.json?app_name=test2&pscope=update&value=test",
"apimethod": "POST",
"basepath": "https://app.platformaerp.com",
"filepath": "/srs/102.xml",
"name": "102",
"id": "102",
"opts": null,
"session_id": "8336fed7-5bcb-44e6-8e17-ca108a8c9c33",
"label": "102",
"description": null,
"cache": null,
"executed_at": "2024-05-13T22:52:33.6256609Z",
"acl": "app_test2",
"tables": [],
"def": [],
"data": {
"update": []
}
}
|
Bash |
---|
| curl.exe -H "Authorization:Token {token}" {host}/api/srs/102/test.json?pscope=delete
|
JSON |
---|
| {
"success": true,
"message": "delete [email protected] test\n",
"apipath": "/api/srs/102/test.json?app_name=test2&pscope=delete&value=test",
"apimethod": "POST",
"basepath": "https://app.platformaerp.com",
"filepath": "/srs/102.xml",
"name": "102",
"id": "102",
"opts": null,
"session_id": "450987bc-71c1-4c0b-b5f5-cc7816fc18c6",
"label": "102",
"description": null,
"cache": null,
"executed_at": "2024-05-13T22:52:33.9596123Z",
"acl": "app_test2",
"tables": [],
"def": [],
"data": {
"delete": []
}
}
|