Datasnap.DSService.TDSRESTService
Delphi
TDSRESTService = class(TDSService)
C++
class PASCALIMPLEMENTATION TDSRESTService : public TDSService
Properties
Type | Visibility | Source | Unit | Parent |
---|---|---|---|---|
class | public | Datasnap.DSService.pas Datasnap.DSService.hpp |
Datasnap.DSService | Datasnap.DSService |
Description
REST service implementation.
Request methods are mapped to CRUD operations as follows:
- GET: /MethodClass/MethodName/inputParameter[/inputParameter]*
- JSON request: {"execute":{"MethodClass.MethodName":[inputParameter[,inputParameter]*]}}
- PUT: /MethodClass/MethodName/inputParameter[/inputparameter]* and [content]
- JSON request: {"execute":{"MethodClass.acceptMethodName":[inputParameter[,inputParameter]*[,JSONValue]}}
- POST: /MethodClass/MethodName/inputParameter[/inputparameter]* and [content]
- JSON request: {"execute":{"MethodClass.updateMethodName":[inputParameter[,inputParameter]*[,JSONValue]}}
- DELETE: /MethodClass/MethodName/inputParameter[/inputParameter]*
- JSON request: {"execute":{"MethodClass.cancelMethodName":[inputParameter[,inputParameter]*]}}
For example, to manage a database connection you could use:
- PUT message http://mySite.com/datasnap/rest/Test/Connection/MSSQL1 results in the JSON request
{"execute":{"Test.acceptConnection":["MSSQL1"]}}
- POST message http://mySite.com/datasnap/rest/Test/Connection/MSSQL2 results in the JSON request
{"execute":{"Test.updateConnection":["MSSQL2"]}}
- GET message http://mySite.com/datasnap/rest/Test/Connection results in the JSON request
{"execute":{"Test.Connection":[]}}
- DELETE message http://mySite.com/datasnap/rest/Test/Connection results in the JSON request
{"execute":{"Test.cancelConnection":[]}}
You can implement those methods as follows:
acceptConnection
opens a connection called "MSSQL1".updateConnection
closes the existing connection (if any) and opens a new one.Connection
returns the name of the current open connection.cancelConnection
closes the existing connection if any.
Where output or return parameters are defined, they are picked up into a JSON response:
{
"result": [
parameterValue1,
parameterValue2,
// …
]
}
If the server throws an exception, then the JSON response is:
{
"error": "Error message."
}